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
Post a Comment