Can anyone help me with performSelectorInBackground
? I want to reload table with updated data in performSelectorInBackground
.
Asked
Active
Viewed 4,931 times
0
-
8No UI updates in background. UI changes must be performed on main thread. – Swapnil Luktuke Mar 20 '12 at 09:12
2 Answers
4
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
}
0
All the UI functionalities should be done in the main thread. So you have to reload the UITableView in main thread only.

Ilanchezhian
- 17,426
- 1
- 53
- 55
-
Looks like a great comment! But maybe you have a look at the question! – Alex Cio Apr 29 '15 at 09:54