再描画:どのような糸でloadDidLoadコントローラの呼び出し方法では、UIViewの
- (void)viewDidLoad {
[super viewDidLoad];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadImages) object:nil];
[self.operationQueue addOperation:operation];
[operation release];
}
画像をダウンロードloadImages方法を、それを示しています
仕事- (void) loadImages {
@synchronized (self) {
// download image...
// ...
// and next:
UIImageView *imageView = [imageViews objectAtIndex:currentImageIndex];
[imageView performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
[imageView performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageWithData:imageData] waitUntilDone:YES];
}
//...
}
ショービュー初めてならば、次回のI画像を表示するにはiphoneを回転させる必要があります。 なぜ表示が再描画されないのですか?
私はアドバイスに従って、このコードを試してみました:
// imageButton is a UIView with button, image and label
NSData *imageData = [[HttpClient sharedInstance] getResourceWithCache:thumbPath];
[imageButton performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageWithData:imageData] waitUntilDone:YES];
[imageButton performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
[imageButton drawRect:imageButton.frame];
が、動作しません。
最初に画像を設定してからsetNeedsDisplayを実行するとどうなりますか? – yinkou
他に何を同期させていますか?これは、特にダウンロードのような長い操作では、非常に危険です。デバッガを使用する - ブレークポイントをアタッチして2回目または3回目の実行時に有効にし、* whole * loadImagesコードをチェックします。 – Eiko
今私はコールセレクタの順番を変えたら何が起きているのか確認できません。それはうまくいかないと思いますが、試してみます。誰かがビューコードに画像を設定した後に、スレッドからビューとサブビューを再描画する方法のサンプルコードを表示すると感謝しています。 –