ios - UIPickerView not showing data correctly (Only Show "?") -
forgive me if question has been discussed previously.
have problem displaying data in uipickerview, it display question mark "?".
header file.h
#import <uikit/uikit.h> @interface custompickerviewcontroller : uiviewcontroller <uipickerviewdelegate, uipickerviewdatasource> { nsmutablearray *arraycolors; } @property (strong, nonatomic) iboutlet uipickerview *kotapicker; @end
impl.m
- (nsinteger)numberofcomponentsinpickerview:(uipickerview *)pickerview { return 1; } - (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component { return [arraycolors count]; } - (nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row { return [arraycolors objectatindex:row]; } - (void)pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component { nslog(@"the data %@", [arraycolors objectatindex:row]); } - (void)viewdidload { [super viewdidload]; arraycolors = [[nsmutablearray alloc] init]; [arraycolors addobject:@"red"]; [arraycolors addobject:@"orange"]; [arraycolors addobject:@"yellow"]; [arraycolors addobject:@"green"]; [arraycolors addobject:@"blue"]; [arraycolors addobject:@"indigo"]; [arraycolors addobject:@"violet"]; // additional setup after loading view nib. }
ok, problem solved, problem incorrect delegate method,
the method have used (for loading data) not delegate method,
- (nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row
try method instead, (must work)
-(nsstring *) pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component{ return [arraycolors objectatindex:row]; }
Comments
Post a Comment