我有这段dispatch_queue
代码用于发出 3 个不同的数据请求。然后我tableView
在主线程上更新。我还能在主线程中放什么?我正在使用它[self requestExtendedData];
从 Web 服务下载数据,然后将其解析并设置为 UILabels 等...
我的问题是:如果我[self requestExtendedData];
在后台线程中运行,如何在主线程中使用此数据中的内容更新 UILabel?我应该把其他所有东西都放在主线程区域吗?所有的 UIView、UILabels 和 UIButton 对象等...
谢谢您的帮助
dispatch_queue_t jsonParsingQueue = dispatch_queue_create("jsonParsingQueue", NULL);
// execute a task on that queue asynchronously
dispatch_async(jsonParsingQueue, ^{
[self requestUserData]; // request user comments data
[self requestExtendedData]; // request extended listing info data
[self requestPhotoData]; // request photo data
// once this is done, if you need to you can call
// some code on a main thread (delegates, notifications, UI updates...)
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
});
// release the dispatch queue
dispatch_release(jsonParsingQueue);