iphone - iOS - How to print value in textfield using delegate -
i new ios. have problem have solution it? not able print json value in textfield contactviewcontroller.m
file:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. fname.text=@"hello"; }
after view loaded hello value shown in text box, when call list button json values:
-(ibaction)list:(id)sender{ vedant=[[webserviceviewcontroller alloc]init]; [vedant listcontacts]; }
then webserviceviewcontroller.m
pass jsonresponse same file i.e contactviewcontroller.m
, parse json value , print not shows value in text field
-(void)allcontacts:(nsstring *)jsonresponse{ nslog(@"%@",jsonresponse); nsdata *jsondata = [jsonresponse datausingencoding:nsasciistringencoding]; // nserror *err; nsdictionary *json = [nsjsonserialization jsonobjectwithdata:jsondata options:kniloptions error:&err]; int acccount =[json count]; for(int i=0;i<acccount;i++){ nsdata *jsondata = [jsonresponse datausingencoding:nsasciistringencoding]; // // nslog(@"%@",jsonresponse); nserror *err; nsdictionary *json = [nsjsonserialization jsonobjectwithdata:jsondata options:kniloptions error:&err]; nsstring *firstname = [nsstring stringwithformat:@"%@", [[json objectatindex:i] objectforkey:@"first_name"]]; nslog(@"%@",firstname); //this prints actual first name in console fname.text=firstname; nslog(@"%@",fname.text); //it prints "(null)" in console } }
do need create delegate pass value?
yes, of creating such delegate article or example.
check if fname
isn't nil
. if forgot connect in interface builder, fname
nil
, messages sent (like settext:
) ignored.
Comments
Post a Comment