3 つの異なるデータ要求を行うために使用しているこのdispatch_queue
コードがあります。tableView
次に、メインスレッドで更新しています。メインスレッドには他に何を入れることができますか? これを使用し[self requestExtendedData];
てWebサービスからデータをダウンロードし、それを解析してUILabelsなどに設定しています...
私の質問は:[self requestExtendedData];
バックグラウンド スレッドで実行している場合、メイン スレッドでこのデータのコンテンツを使用して UILabels を更新するにはどうすればよいですか? 他のすべてをメインスレッド領域に配置する必要がありますか? すべての 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);