私はUITableViewを使ってiPhone用のシンプルなTwitterクライアントを実装しています。その細胞はのtableViewに表示されたとき、私は私のフィード内の各Twitterユーザーの写真をフェッチ:cellForRowAtIndexPath:バックグラウンドスレッドの完了後にUIを更新する
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *profileImage = [tweet.user getProfileImageDataInContext:self.fetchedResultsController.managedObjectContext];
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image = profileImage;
});
});
ここでは、画像を取得するためのコードです:ここでは
if (!self.profileImage)
{
sleep(2);
self.profileImage = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.profileImageURL]];
//// if we recently scheduled an autosave, cancel it
[TwitterUser cancelPreviousPerformRequestsWithTarget:self selector:@selector(autosave:) object:context];
// request a new autosave in a few tenths of a second
[TwitterUser performSelector:@selector(autosave:) withObject:context afterDelay:0.2];
}
return [UIImage imageWithData:self.profileImage];
は、私はエラーです取得:
twitterClient[10743:15803] bool _WebTryThreadLock(bool), 0x59bac90: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
私はそれは私がテーブルビューをスクロールするとき、それはまだ取り込まれていない場合、これは非常に迅速に起こることも言及する価値だと思います。
ダウンロードが完了したらメインUIを更新したいと思います。 iPhone用の実際のTwitterアプリは、これを非常にうまく処理します。
提案がありますか?
クラッシュするコールを表示できますか?イメージをプッシュするためにメインスレッド(GCDでこれを行う場合はメインキュー経由)にホッピングしてください。 – Tommy
ありがとう、トミー。私は実際のコールとクラッシュで質問を編集しました。 – toddbranch