ios - UIPickerView data problems -
all,
i have external class file :
#import <foundation/foundation.h> @interface globalvars : nsobject { nsarray *alllocationsid; nsarray *alllocationscity; } @property(nonatomic, copy) nsarray *alllocationsid; @property(nonatomic, copy) nsarray *alllocationscity; @end
and data , put in array :
globalvars *global = [[globalvars alloc] init]; global.alllocationsid = [[responseobject valueforkey:@"data"] valueforkey:@"id"]; global.alllocationscity = [[responseobject valueforkey:@"data"] valueforkey:@"name"]; nslog(@"%@", global.alllocationscity); nslog(@"%@",global.alllocationsid); nslog(@"%lu",(unsigned long)global.alllocationsid.count);
that brings in correct amount of .count 14, gets data global class file.
but in numberofrowsincompent global.allocationsid.count brings in 0, no wonder why picker view doesn't show!
- (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component { globalvars *global = [[globalvars alloc] init]; nslog(@"%lu",(unsigned long)global.alllocationsid.count); nsinteger numrows = global.alllocationsid.count; return numrows;
any ideas ?
in numberofrowsincomponent
should not allocate globalvars.
so in .h
globalvars *global;
then in .m
global = [[globalvars alloc] init]; global.alllocationsid = [[responseobject valueforkey:@"data"] valueforkey:@"id"]; global.alllocationscity = [[responseobject valueforkey:@"data"] valueforkey:@"name"]; nslog(@"%@", global.alllocationscity); nslog(@"%@",global.alllocationsid); nslog(@"%lu",(unsigned long)global.alllocationsid.count);
then in numberofrowincomponent
- (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component { nslog(@"%lu",(unsigned long)global.alllocationsid.count); nsinteger numrows = global.alllocationsid.count; return numrows; }
Comments
Post a Comment