self.tableView reloadData not working after successful call in AFNetworking

与世无争的帅哥 提交于 2019-12-29 07:36:05

问题


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?


回答1:


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

dispatch_sync(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});



回答2:


Always reload on the main queue:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});


来源:https://stackoverflow.com/questions/24939434/self-tableview-reloaddata-not-working-after-successful-call-in-afnetworking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!