0
votes

When I send a network request on afnetworking i get the results in a completion block. In this block I parse and using the delegate of that class I tell the view controller to check for the data.

The VC calls reloadData on the table view. The only thing is that if I use a delegate reloadData is hit or miss (sometimes it works). But if I post a notification then it works perfectly.

I think the issue has to do with the delegate being called from the afNetworking block since it is on a different thread. I don't put it there but I think AFN multithreads the request automatically.

Why is this issue happening?

2
you calling afnetworking on secondary thread? - Durgaprasad
No. I figured they multiThread for me - William Falcon
UI operations has to be performed in Main thread. Is that the issue here? - Raj

2 Answers

1
votes

@Durgaprasad is right. May be the Copy of him. Still adding some conditions to it.Try ,

if ([NSThread isMainThread]) 
{
  [self.tableView reloadData];
}
else 
{
   [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];

}
0
votes

I consider you called afnetworking on secondary thread. And from that calling [tableView reloadData]; This will give crash since you cant change UI from any other thread. You need to use main thread. Try this for that.

   [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];