ios - How to populate the UITableView contents for the first time? -


i have uitableview in viewcontroller. first time run application, table empty. table filled, when go through other views , view(which has uitable). use following solution, not work. put part of code in viewwillappear , viewdidload, not working.

dispatch_async(dispatch_get_main_queue(), ^{         [self getthetablecontentfromserver];         [self.tableview reloaddata]; // reload selected cell      }); 

anyone knows how can populate content of table first time? here getthetablecontentfromserver method:

-(void)getthetablecontentfromserver{     nsurl *url = [nsurl urlwithstring:@"http://exampledomain.com/data"];     config = [nsurlsessionconfiguration defaultsessionconfiguration];      nsurlsession *session = [nsurlsession sessionwithconfiguration:config delegate:nil delegatequeue:[nsoperationqueue mainqueue]];     [[session datataskwithurl:url completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) {         data= [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers error:nil];             [self.tableview reloaddata];     }       ] resume]; } 

you should put call getthetablecontentfromserver on background thread. once completes send nsnotification viewcontroller call reloaddata.


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -