Switch your code to this:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_queue_t myqueue = dispatch_queue_create("queue", NULL);
dispatch_async(myqueue, ^{
//Whatever is happening in the fetchedData method will now happen in the background
[self fetchedData:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tbl reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
});
You don't want to call the fetchData
method on the main thread. If you use the code above, nothing in the fetchedData
method will happen on the main thread, so make sure you don't update the UI or anything in there.
Just a suggestion, I wouldn't use the name "queue"
for your dispatch_queue
. The names of the queues across the app need to be unique, so I'd call it something like "your.bundle.id.viewcontrollername"
just to avoid issues later.