Having issue with prefetching data and displaying on uitableview. So basically I want to block the main UI thread so that I can get data from web. I am using serial dispatch queue for synchronizing. Also, dispatch queue block is executing another block that fetches data from web. The code for executing is written in viewdidload:
dispatch_queue_t queue= dispatch_queue_create("myQueue", NULL);
CMStore *store = [CMStore defaultStore];
// Begin to fetch all of the items
dispatch_async(queue, ^{
[store allObjectsOfClass:[Inventory class]
additionalOptions:nil
callback:^(CMObjectFetchResponse *response) {
//block execution to fetch data
}];
});
dispatch_async(queue, ^{
//load data on local data structure
[self.tableView reloadData];
});
You should NEVER perform any UI-related code anywhere other than in the main thread/queue.
Always perform every UI-related code (like
reloadDataon anUITableView) on the main thread/queue. In your example I guess you should also reload the tableview only when your data has been fetched, so in the completion block, and not before the callback has been called.