0

私はこのように私のcellViewsを構築しています:

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString* cellIdentifier=@"cell";

    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
    }

    UIImageView cellView = [[UIImageView alloc] initWithFrame:rectCellFrame];

    NSError* error=nil;
    NSData* imageData = [NSData dataWithContentsOfURL:imageArray[indexPath.row] options:NSDataReadingUncached error:&error];

    UIImage* theImage= [UIImage ImageWithData:imageData];

    [cellView setImage:theImage];

    [cell addSubView:cellView];

    .
    .
    .
    .

    [cell addSubView:moreViews];

}

読み込み時間は (画像がキャッシュされている場合でも) 非常に遅いため、これを並行処理する必要があります。しかし、UIViews/UIImageViews で自分のコードを引き続き使用したいと思います。プレースホルダーを表示する方法はありますか?関連する場合、つまり、すべてのサブビューからの cellView の構築が完了したら、プレースホルダーの代わりに画像を更新しますか?

4

1 に答える 1

1

もちろん。非同期タスクですべての重い低速コードをセットアップできます。画像をダウンロードする必要があるときは、多くの場合ダウンしています。Table Views の WWDC ビデオの少なくとも 1 つでカバーされていると確信していますが、どれがどれで、どれくらい古いものになるかはわかりません。

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // place holder image for the moment
    [cellView setImage:placeHolderImage];

    // run code to get the real image in asynchronous task 
    dispatch_async(self.contextQueue, ^{
        UIImage *realImage = [thingy imageFromTimeConsumingTask];
        // update cell on main thread (you need to do all UI stuff on main thread)
        dispatch_async(dispatch_get_main_queue(), ^{
            [cellView setImage:realImage];
        });
    });
}
于 2013-03-12T19:23:23.027 に答える