ios - UITableView Not updating within dispatch_async -
i trying tableview update via async code
dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^(void) { nsstring *mainurl = @"http://myurl.com/api/"; nsstring *firstprefix = @"type=topdeals&device="; nsstring *deviceidforurl = [nsstring stringwithformat:@"%@", devicetoken]; nsstring *stringtogotoencoder = [nsstring stringwithformat: @"%@%@", firstprefix, deviceidforurl]; nsdata *plaindata = [stringtogotoencoder datausingencoding:nsutf8stringencoding]; nsstring *base64string = [plaindata base64encodedstringwithoptions:0]; nsstring *returnurl = [nsstring stringwithformat:@"%@%@", mainurl, base64string]; nsurl *returncompletedurl = [[nsurl alloc] initwithstring:returnurl]; //nsurl *request = [nsurl urlwithstring:returncompletedurl]; nsdata *data = [nsdata datawithcontentsofurl:returncompletedurl]; nserror *error; nsmutabledictionary *responseobject = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers error: &error]; nslog(@"%@", responseobject); alllogos = [[responseobject valueforkey:@"data"] valueforkey:@"logo"]; allcontent = [[responseobject valueforkey:@"data"] valueforkey:@"content"]; allpostode = [[responseobject valueforkey:@"data"] valueforkey:@"postcode"]; allname = [[responseobject valueforkey:@"data"] valueforkey:@"name"]; alladdress = [[responseobject valueforkey:@"data"] valueforkey:@"address"]; alladdress2 = [[responseobject valueforkey:@"data"] valueforkey:@"address2"]; alllat = [[responseobject valueforkey:@"data"] valueforkey:@"lat"]; alllong = [[responseobject valueforkey:@"data"] valueforkey:@"lng"]; allstart = [[responseobject valueforkey:@"data"] valueforkey:@"start"]; allfinish = [[responseobject valueforkey:@"data"] valueforkey:@"finish"]; allstartnice = [[responseobject valueforkey:@"data"] valueforkey:@"nicestart"]; allfinishnice = [[responseobject valueforkey:@"data"] valueforkey:@"nicefinish"]; dispatch_sync(dispatch_get_main_queue(), ^(void) { nslog(@"%@", allcontent); [self.tableview reloaddata]; }); }); my table view not updating via command.
here's .h file
@interface viewcontroller : uiviewcontroller <uitableviewdelegate, uitableviewdatasource, uipickerviewdelegate, cllocationmanagerdelegate> { cllocationmanager *locationmanager; } @property (weak, nonatomic) iboutlet uiactivityindicatorview *spinner; @property (weak, nonatomic) iboutlet uitableview *tableview; @property (weak, nonatomic) iboutlet uilabel *locationlabel; @property (weak, nonatomic) iboutlet uibutton *settingsbutton; @property (weak, nonatomic) iboutlet uiswitch *outswitch; @property (weak, nonatomic) iboutlet uilabel *latestdealslabel; @property (weak, nonatomic) iboutlet uilabel *blackout; my table view datasource "allcontent" global nsarray. can see in log "allcontent" updated correct content before updating tableview.
any appreciated.
do not call dispatch_sync function if executing task on same queue going deadlock mode.
so instead of that
dispatch_sync(dispatch_get_main_queue(), ^(void) { //update ui in main thread }); this link helpful
Comments
Post a Comment