1

このコードは、カスタム セルの要素を設定するセル初期化ルーチンにあります。Web から画像を非同期的に取得します。しかし、完了したら再描画する必要があります。

これは私のコードスニペットです:

dispatch_async(myCustomQueue, ^{

    //Look for the image in a repository, if it's not there
    //load the image from the web (a slow process) and return it
    mCover.image = [helperMethods imageManagerRequest:URL];

    //Set the image to be redrawn in the next draw cycle
    dispatch_async(dispatch_get_main_queue(), ^{
        [mCover setNeedsDisplay];
    });

});

ただし、UIImageView は再描画されません。セル全体も再描画しようとしましたが、それもうまくいきません。あなたの助けに感謝します。私はしばらくの間、これを修正しようとしてきました!

4

1 に答える 1

3

の代わりに、Apple がドキュメントsetNeedsDisplayで言及しているように、メイン スレッドにイメージを設定する必要があります。

注: ほとんどの場合、UIKit クラスはアプリケーションのメイン スレッドからのみ使用する必要があります。これは特に、UIResponder から派生したクラス、または何らかの方法でアプリケーションのユーザー インターフェイスを操作することを伴うクラスに当てはまります。

これで問題が解決するはずです:

dispatch_async(myCustomQueue, ^{

    //Look for the image in a repository, if it's not there
    //load the image from the web (a slow process) and return it
    UIImage *image = [helperMethods imageManagerRequest:URL];

    //Set the image to be redrawn in the next draw cycle
    dispatch_async(dispatch_get_main_queue(), ^{
        mCover.image = image;
    });

});
于 2013-02-04T03:27:14.873 に答える