objective c - iPhone App - NSArray Issue -
objective c - iPhone App - NSArray Issue -
hi learning how code in objective-c. want store values of textfields in view in array:
nsarray* answers = [nsarray arraywithobjects:fluidintake.text, sleepquality.text, sleepquantity.text, mentalrecovery.text, physicalrecovery.text, pretrainingenergy.text, musclesoreness.text, generalfatigue.text, nil]; is possible? if not there cleaner way store multiple textfield values without having assign them nsstring variable..
update:
here function in view controller:
-(ibaction)postdata:(id)sender{ diary = [[personaldiary alloc]init]; nsarray* answers = [nsarray arraywithobjects:fluidintake.text, sleepquality.text, sleepquantity.text, mentalrecovery.text, physicalrecovery.text, pretrainingenergy.text, musclesoreness.text, generalfatigue.text, nil]; [diary post:answers to: @"http://www.abcdefg.com/test.php"]; } it triggered upon button press. should store 8 values input textfields in nsarray , pass function in model class which @ min attempts print first element in array (i.e. first textfield value):
-(void) post:(nsarray*) ans to:(nsstring*) link{ nslog(@"%@", ans[0]); } but doesn't, prints : personaldiary[37114:207] __nsarrayi
you incorrectly indexing array in method , using wrong kind of string.
-(void) post:(nsarray*) ans to:(nsstring*) link{ nsstring* = "hello"; nslog(@"%s%d", a, ans[0]); } ans[0] print pointer address of nsarray , not access elements. access array need utilize objectatindex:. nsstring literals need prefixed @. , when print kind of objective-c object utilize %@ format. not safe access objects of array without checking count first.
-(void) post:(nsarray*) ans to:(nsstring*) link{ nsstring* = @"hello"; nslog(@"%@ %@", a, [ans objectatindex:0]); //or print entire array nslog(@"%@", ans); } iphone objective-c xcode nsarray
Comments
Post a Comment