0

画像のグリッドに AQGridView を使用しています。ダウンロード中の特定の画像にプログレス バーを重ねる必要があります。問題は、その画像セルをスクロールして表示から外すと、進行状況バーが別のセルにも表示されることです。これはセルが再利用されているためだと思います。

特定のセルを再利用しないようにマークする方法はありますか?

4

3 に答える 3

2

お願い、それはやめて。でセルを更新する必要があります- gridView:cellForItemAtIndex:。これは、表示されるすべてのセルに対して呼び出されます。

何かのようなもの:

- (AQGridViewCell *)gridView:(AQGridView *)aGridView cellForItemAtIndex:(NSUInteger)index
{
     AQGridViewCell *cell;

     // dequeue cell or create if nil
     // ...

     MyItem *item = [items objectAtIndex:index];
     cell.progressView.hidden = !item.downloading;

     return cell;
}
于 2011-04-29T07:33:55.610 に答える
0

UITableViewCells は、メモリ使用量を減らして効率を上げるために、デフォルトで tableview によって再利用されるため、再利用動作を無効にしないでください (可能ですが)。セルの再利用を無効にする代わりに、セルに読み込み中の画像が含まれているかどうかを明示的に確認し、必要に応じてフラグを使用して進行状況バー (および進行状況) を表示/非表示にする必要があります。

それでも再利用動作を無効にする必要がある場合は、dequeueTableCellWithIdentifier を呼び出さずに、tableviewcells の新しいインスタンスを作成し、それへの参照を cellForRowAtIndexPath に明示的に保持します。ただし、これはうまくスケーリングできず、特にテーブルビューに多くのエントリがある場合は、より多くのメモリを消費することになります。

于 2011-03-24T07:33:26.160 に答える
-1

これが私がやった方法です。私の派生セルクラスには、インスタンス変数があります

BOOL dontReuse;

AQGridView のカテゴリを作成し、以下のように dequeueReusableCellWithIdentifier を定義しました。

    - (AQGridViewCell *) dequeueReusableCellWithIdentifier: (NSString *) reuseIdentifier AtIndex:(NSUInteger) index
{
    /* Be selfish and give back the same cell only for the specified index*/
    NSPredicate* predTrue = [NSPredicate predicateWithFormat:@"dontReuse == YES"];
    NSMutableSet * cells = [[[_reusableGridCells objectForKey: reuseIdentifier] filteredSetUsingPredicate:predTrue] mutableCopy];
    for(AQGridViewCell* cell in cells){
        if(index == [cell displayIndex]) {
            [[_reusableGridCells objectForKey: reuseIdentifier] removeObject: cell];
            return cell;
        }
    }

    NSPredicate* predFalse = [NSPredicate predicateWithFormat:@"dontReuse == NO"];
    cells = [[[_reusableGridCells objectForKey: reuseIdentifier] filteredSetUsingPredicate:predFalse] mutableCopy];

    AQGridViewCell * cell = [[cells anyObject] retain];
    if ( cell == nil )
        return ( nil );

    [cell prepareForReuse];

    [[_reusableGridCells objectForKey: reuseIdentifier] removeObject: cell];
    return ( [cell autorelease] );
}
于 2011-03-25T09:33:49.387 に答える