有人可以帮我performSelectorInBackground
吗?我想用performSelectorInBackground
中的更新数据重新加载表。
最佳答案
您可以做的是,只需在后台线程中获取数据,就可以在获取数据并更新主线程中的tableview后返回主线程。
- (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
}
关于iphone - iPhone + performselector在后台,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9783957/