Reputation: 3136
Can anyone help me with performSelectorInBackground
? I want to reload table with updated data in performSelectorInBackground
.
Upvotes: 0
Views: 4932
Reputation: 16553
What you can do is you just get the data in the background thread and you can return back to main thread once you get the data and update the tableview in main thread.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//All your views cell creations and other stuff
[self performSelectorInBackground:@selector(loadDataThatToBeFetchedInThread:)
withObject:objectArrayThatNeedToFetchData];
}
- (void) loadDataThatToBeFetchedInThread:(NSArray *)objectThatNeedToFetchData
{
//Fetch the data here. which takes place in background thread
[self performSelectorOnMainThread:@selector(updateTableViewWithTheData:)
withObject:responseData
waitUntilDone:YES];
}
- (void) updateTableViewWithTheData:(NSMutableArray *)yourData
{
//Update Data to tableview here
}
Upvotes: 4
Reputation: 17478
All the UI functionalities should be done in the main thread. So you have to reload the UITableView in main thread only.
Upvotes: 0