ios - Response in alert view -


empty value in alertviewi new ios want display response post in alert view.in nslog showed response. need when clicked button alert view can display response.

coding:

-(void) senddatatoserver : (nsstring *) method params:(nsstring *)str{       nsdata *postdata = [str datausingencoding:nsasciistringencoding allowlossyconversion:yes];     nsstring *postlength = [nsstring stringwithformat:@"%lu", (unsigned long)[str length]];      nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring:url]];     nslog(@"%@",str);      [request sethttpmethod:@"post"];     [request setvalue:postlength forhttpheaderfield:@"content-length"];     [request sethttpbody:postdata];      nsurlconnection *theconnection = [nsurlconnection connectionwithrequest:request delegate:self];      if( theconnection ){          mutabledata = [[nsmutabledata alloc]init];     } } 

alerview:

- (ibaction)butt1:(id)sender {      uialertview *alert = [[uialertview alloc] initwithtitle:@"value"                                                     message:@"%@"                                                    delegate:self                                           cancelbuttontitle:@"cancel"                                           otherbuttontitles:@"ok", nil];      [self senddatatoserver :@"post" params:str];      [alert show];  } 

post method delegates: here response in json111 showed in nslog in alert view failed

-(void) connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {     [mutabledata appenddata:data]; }  -(void) connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {     return; }  -(void)connectiondidfinishloading:(nsurlconnection *)connection {       nserror* error111;    json111 = [nsjsonserialization jsonobjectwithdata: mutabledata                                            options:kniloptions                                              error:&error111];     nslog(@"%@",json111);    }   [![emptyvalue in alertview][1]][1] 

change

updated answer

@interface myviewcontroller : uiviewcontroller <uialertviewdelegate>    -(void)connectiondidfinishloading:(nsurlconnection *)connection {   nserror* error111; json111 = [nsjsonserialization jsonobjectwithdata: mutabledata                                        options:kniloptions                                          error:&error111]; nslog(@"%@",json111);  nsarray *temp = [ json111 objectforkey:@"currencies"];   // can directly fetch  nsdictionary *fetchdict = [temp objectatindex:0];   nsdictionary *fetchunit = [temp objectatindex:1];  // can fetch   nsstring * total = [fetchdict objectforkey:@"total"];    nsstring * one_unit = [fetchunit objectforkey:@"one_unit"];    //updated   nsstring *final = [nsstring stringwithformat:@"%@ , %@", total,one_unit];   // in here can assign value alert   uialertview *alert = [[uialertview alloc] initwithtitle:@"value"                                                 message:final                                                delegate:self                                       cancelbuttontitle:@"cancel"                                       otherbuttontitles:@"ok", nil];   alert.tag = 100; [alert show];   }     - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex {    if (alertview.tag == 100) { if (buttonindex == 0)  {    // ok button pressed   //[self senddatatoserver :@"post" params:str]; }else  {    // cancel button pressed } } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -