Shantanu
Shantanu

Reputation: 3136

IPhone+performselector in background

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

Upvotes: 0

Views: 4932

Answers (2)

ipraba
ipraba

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

Ilanchezhian
Ilanchezhian

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

Related Questions