9

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?

Jargen89
  • 480
  • 1
  • 6
  • 19

2 Answers2

40

Always reload on the main queue:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});
meda
  • 45,103
  • 14
  • 92
  • 122
  • I find it odd that I would need this for reloadData, but it isn't necessary in another instance of AFHTTPSessionManager where I have viewControllers perform segues in the success block – Jargen89 Jul 24 '14 at 18:02
20

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

dispatch_sync(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});
Daxesh Nagar
  • 1,405
  • 14
  • 22