Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
672 views
in Technique[技术] by (71.8m points)

ios - self.tableView reloadData not working after successful call in AFNetworking

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Always reload on the main queue:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...