self.tableView reloadData not working after succes

2019-01-26 08:25发布

I have a class that runs similar to the AFHTTPSessionManager component of this tutorial http://www.raywenderlich.com/59255/afnetworking-2-0-tutorial

However, [self.tableView reloadData] is not working for me.

I have the manager implemented as so:

-(void) refresh{
     manager = [[AFHTTPSessionManager...] iniwithBaseURL:...];
     [manager Get:... parameters:... success:^(NSURLSessionDataTask *task, id responseObject){
         //test success values in responseObject
         if(test){
             //Get table data
             [self.tableView reloadData];
         }
     }
     ....
}

However if I run [self.tableView reloadData] in a separate function afterwards, it works just fine. Why is this happening, instead of how it should in the tutorial?

2条回答
男人必须洒脱
2楼-- · 2019-01-26 09:07

Always reload on the main queue:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});
查看更多
唯我独甜
3楼-- · 2019-01-26 09:08

write the [self.tableView reloadData];in the main queue.

dispatch_sync(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});
查看更多
登录 后发表回答