G.P.Reddy G.P.Reddy - 3 months ago 18
Objective-C Question

TableView Not Updating

I have parse the data from

API
response to
UITableView
.But here i get the response in viewDidAppear method,then after completed response i want update the data to TableView but its not updated.I'm following this methods

- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];
// Response here ..Service call //
NSLog(@"viewDidAppear running");
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:TRUE];
}


and also i tried to
[self.tableView reloadData]
but
TableView
not Updated ,can you please suggest me how can i overcome this.Thank you.

Answer

you cannot call UITableView#reloadData from a background thread. So you actually need to schedule just that one on the main thread: call the following methods after webservice call when you get the response after that add this

if (yourArray.count>0)
{
dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});
}

No need of this

- (void)viewDidAppear:(BOOL)animated {

                [super viewDidAppear:animated];
        // Response here ..Service call  //
                NSLog(@"viewDidAppear running");
        [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:TRUE];
    }
Comments