0

Can anyone help me with performSelectorInBackground? I want to reload table with updated data in performSelectorInBackground.

beryllium
  • 29,669
  • 15
  • 106
  • 125
Shantanu
  • 3,086
  • 3
  • 25
  • 32

2 Answers2

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
}
Alex Cio
  • 6,014
  • 5
  • 44
  • 74
ipraba
  • 16,485
  • 4
  • 59
  • 58
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