i have uipickerview being automatically loaded in loaded when user touches uitextfield, @ end of selection user can close uipicker touching "close" have added in inputaccessoryview = toolbar;
. problem need set value chosen in uipicker value of self.textoutlet.text
... attempt here no luck :
- (nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component { return [templist objectatindex:row]; selectedtext = _textoutlet.text;
can please give me ideas on how fix problem? here header code:
#import <uikit/uikit.h> @interface viewcontroller : uiviewcontroller <uipickerviewdatasource, uipickerviewdelegate> @property (strong, nonatomic) nsstring* selectedtext; //the uitextfield text @property nsarray * templist; @end
and here implementation code:
#import "viewcontroller.h" @interface viewcontroller () @property (weak, nonatomic) iboutlet uilabel *mylabel; @property (weak, nonatomic) iboutlet uipickerview *thepicker; @property (weak, nonatomic) iboutlet uitextfield *textoutlet; @end @implementation t3viewcontroller @synthesize templist, selectedtext; // 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]; selectedtext = _textoutlet.text; } - (void)pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component { cgfloat chosenvalue; switch (row) { case 0: chosenvalue = 0.0000233; break; case 1: chosenvalue = 0.0001273; break; case 2: chosenvalue = 0.0012333; break; case 3: chosenvalue = 0.0032204; break; case 4: chosenvalue = 0.0234179; break; case 5: chosenvalue = 0.0002369; break; case 6: chosenvalue = 0.0004442; break; default: chosenvalue = 0; break; } nsnumberformatter *formatter = [[nsnumberformatter alloc]init]; formatter.numberstyle = nsnumberformatterdecimalstyle; formatter.minimumfractiondigits=7; self.mylabel.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:@"3222° f",@"22150° f",@"1260° f",@"12170° f",@"83210° f",@"84415° f",@"10120° f", nil]; // hides picker upon initiation of view self.thepicker.hidden = yes; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } -(void)doneclicked:(id) sender { [_textoutlet resignfirstresponder]; //hides pickerview } - (void)textfielddidbeginediting:(uitextfield *)textfield { if (textfield == self.textoutlet) { self.textoutlet.inputview = _thepicker; self.thepicker.hidden = no; uitoolbar* toolbar = [[uitoolbar alloc] init]; toolbar.barstyle = uibarstyleblacktranslucent; [toolbar sizetofit]; //to make done button aligned right uibarbuttonitem *flexiblespaceleft = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil action:nil]; uibarbuttonitem* donebutton = [[uibarbuttonitem alloc] initwithtitle:@"done" style:uibarbuttonitemstyledone target:self action:@selector(doneclicked:)]; [toolbar setitems:[nsarray arraywithobjects:flexiblespaceleft, donebutton, nil]]; self.textoutlet.inputaccessoryview = toolbar; } } @end
in first snippet of code, setting selectedtext
after return statement. line of code never executed.
Comments
Post a Comment