i have uipicker shown when user selects specific uitextfield. problem having this: have added working picker called mypicker
, text field called field
.
i have looked @ several questions asking getting picker pop instead of picker, have not come across 1 right answer me.
i able mypicker
show changing text field's inputview
problem cannot figure out way add accessory toot bar perhaps "done" button.
for testing purposes added simple button action :
self.mypicker.hidden = yes; [_field resignfirstresponder];
but giving me weird, non animated doesn't feel right.
here code this:
#import "viewcontroller.h" @interface mixerhpviewcontroller () @property (weak, nonatomic) iboutlet uilabel *testlabel; @property (weak, nonatomic) iboutlet uitextfield *field; @property (weak, nonatomic) iboutlet uipickerview *mypicker; @property (weak, nonatomic) iboutlet uitextfield *field2; - (ibaction)takebutton:(id)sender; @end @implementation viewcontroller @synthesize templist; // returns number of 'columns' display. - (nsinteger)numberofcomponentsinpickerview:(uipickerview *)pickerview { return 1; } // returns # of rows in each component.. - (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component { return [templist count]; } - (nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component { return [templist objectatindex:row]; } - (void)pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component { cgfloat chosenvalue; switch (row) { case 0: chosenvalue = 0.0000765; break; case 1: chosenvalue = 0.0000123; break; case 2: chosenvalue = 0.0000982; break; case 3: chosenvalue = 0.0000933; break; case 4: chosenvalue = 0.0000058; break; case 5: chosenvalue = 0.0000121; break; case 6: chosenvalue = 0.0000132; break; default: chosenvalue = 0; break; } nsnumberformatter *formatter = [[nsnumberformatter alloc]init]; formatter.numberstyle = nsnumberformatterdecimalstyle; formatter.minimumfractiondigits=7; self.testlabel.text = [formatter stringfromnumber:@(chosenvalue)]; } - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; // additional setup after loading view. templist = [[nsarray alloc] initwithobjects:@"option a",@"option b",@"option c",@"option d",@"option f",@"option g",@"option h", nil]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (void)textfielddidbeginediting:(uitextfield *)textfield { if( textfield == self.field ) { self.field.inputview = _mypicker; } } - (ibaction)takebutton:(id)sender { self.mypicker.hidden = yes; [_field resignfirstresponder]; } @end
you can dismiss animations:
- (ibaction)takebutton:(id)sender { [uiview beginanimations:nil context:nil]; [uiview setanimationduration:0.5]; [uiview setanimationdelay:1.0]; [uiview setanimationcurve:uiviewanimationcurveeaseout]; //you can customize self.mypicker.frame = cgrectmake(-100, -100, 100, 200); [uiview commitanimations]; [self.mypicker removefromsuperview]; [_field resignfirstresponder]; }
Comments
Post a Comment