objective c - Json data is not updated in uitableview ios? -



objective c - Json data is not updated in uitableview ios? -

i’ building ios article reading app using storyboards.i’m using afnetworking library parse json in table view.

i facing problem updated articles not displaying in table view means if in json new articles added not updated in table view.

here code:

- (void)viewdidload { [super viewdidload]; [self.tableview reloaddata]; x=2; tempjson = [[nsmutablearray alloc] init]; [self.tableview reloaddata]; nsstring *jsonlink=[nsstring stringwithformat:@"http://cccccc.com/json.php?token=hashg156349&page=1"]; nsurl *url = [[nsurl alloc] initwithstring:jsonlink]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestreturncachedataelseload timeoutinterval:30.0]; [request settimeoutinterval:120]; afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request]; operation.responseserializer = [afjsonresponseserializer serializer]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) { dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ nsarray *jsonarray = (nsarray *)responseobject; dispatch_async(dispatch_get_main_queue(), ^{ (nsdictionary *dic in jsonarray) { json *json = [[json alloc] initwithdictionary:dic]; [tempjson addobject:json]; } self.jsons = [[nsarray alloc] initwitharray:tempjson]; // tempninjas = nil; [self.tableview reloaddata]; self.tableview.separatorcolor = [uicolor colorwithred:190/255.0 green:190/255.0 blue:190/255.0 alpha:1.0]; }); }); } failure:^(afhttprequestoperation *operation, nserror *error) { uialertview *alertview = [[uialertview alloc] initwithtitle:@"error" message:[error localizeddescription] delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alertview show]; }]; [operation start]; }

first seek phone call info server , fetch info . after load table view fetched info this.

-(void)viewwillappear{ x=2; tempjson = [[nsmutablearray alloc] init]; nsstring *jsonlink=[nsstring stringwithformat:@"http://cccccc.com/json.php?token=hashg156349&page=1"]; nsurl *url = [[nsurl alloc] initwithstring:jsonlink]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestreturncachedataelseload timeoutinterval:30.0]; [request settimeoutinterval:120]; afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request]; operation.responseserializer = [afjsonresponseserializer serializer]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) { dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ nsarray *jsonarray = (nsarray *)responseobject; dispatch_async(dispatch_get_main_queue(), ^{ (nsdictionary *dic in jsonarray) { json *json = [[json alloc] initwithdictionary:dic]; [tempjson addobject:json]; } self.jsons = [[nsarray alloc] initwitharray:tempjson]; // tempninjas = nil; self.tableview.separatorcolor = [uicolor colorwithred:190/255.0 green:190/255.0 blue:190/255.0 alpha:1.0]; }); }); } failure:^(afhttprequestoperation *operation, nserror *error) { uialertview *alertview = [[uialertview alloc] initwithtitle:@"error" message:[error localizeddescription] delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alertview show]; }]; [operation start]; [self.tableview reloaddata]; }

ios objective-c json uitableview afnetworking

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -