self.tableView reloadData not working after successful call in AFNetworking

13,414

Solution 1

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

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

Solution 2

Always reload on the main queue:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});
Share:
13,414
Jargen89
Author by

Jargen89

I love puzzles

Updated on June 04, 2022

Comments

  • Jargen89
    Jargen89 about 2 years

    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?

  • rmaddy
    rmaddy almost 10 years
    Don't repeat answers.
  • Jargen89
    Jargen89 almost 10 years
    actually, this one came first. so im giving it the checkmark
  • Jargen89
    Jargen89 almost 10 years
    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
  • meda
    meda almost 10 years
    No mine was first but thats okay
  • Jargen89
    Jargen89 almost 10 years
    I guess I will just give as many upvotes as I reasonably can then :P
  • meda
    meda almost 10 years
    Dont worry about it, most important is your problem is solved
  • Kyle Redfearn
    Kyle Redfearn about 9 years
    This isn't a duplicate answer. One calls for dispatch_ASYNC the other for dispatch_SYNC, very different.