iPhone+后台执行选择器

标签 iphone ios ipad

谁能帮我解决 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/

相关文章:

ios - 从 Windows 加载的 Apple 证书

ios - ios 中的 uidatepicker 24 小时格式

iphone - 移植 iphone 应用程序。如果您要从头开始重新启动您的应用程序,您会采取哪些不同的做法?

iOS - Storyboard - 本地化 - 修改 Storyboard后,如何同步到其他语言的 Storyboard?

iphone - 没有接口(interface)的实例类或方法?

css - 页面在 Ipad 中不居中

ios - 响应式布局在 iPhone 7 和 iPad 7 中无法正确缩放

iphone - 没有边框的圆角矩形 UIButton

ios - 尝试将机器人添加到 xcode 服务器 : "This server cannot build for any platform" 时出错

ios - 如何在移动 slider 时更改按钮的背景颜色?