谁能帮我解决 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+后台执行选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9783957/