2012-02-01 12 views
0

dequeueReusableCellWithIdentifierメソッドが古いセルを取得するために新しいセルを作成するのではなく、新しいセルを作成する必要がある場合、私は明示的に言って、show = YESかshow = NOをセルにつけたいので、セルは古いグラフィックを持ったセルを使って終わらず、イメージを取得することになります。私の見解。UITableView dequeuReuseableCellWithIdentifier、グラフィックスが表示されないようにしたい場合

この場合、私はPopover内にUITableViewを持っています。これはグループ化されたテーブルです。グループには、データに応じて2〜4セルがあります。私は連絡先アプリケーションのようにUITableViewCellStyleValue2を使用しています。グループの最初のセルのセルの右側に、データに応じて画像を追加したいとします。しかし、テーブルをスクロールすると、デキューされたセルがピックアップされ、最初のセルでもないセルの右側にイメージの1つが表示されます。私はUITableViewCellサブクラスを作成せず、このポイントを追加する必要があるかどうかわからないので、私はセルに追加しているimageViewを制御します。

は、だからここcellForRowAtIndexPathメソッドの重要な部分です:

if (row == 0) { 
    UIImage *dot; 
    if (aTarget.importance == TargetImportanceHigh) { 
     dot = [UIImage imageNamed:@"dot_red.png"]; 
    } 
    else if (aTarget.importance == TargetImportanceLow) { 
     dot = [UIImage imageNamed:@"dot_yellow.png"]; 
    } 
    else { 
     dot = [UIImage imageNamed:@"dot_black.png"]; 
    } 
    UIImageView *imgView = [[UIImageView alloc] initWithImage:dot]; 
    imgView.frame = CGRectMake(cell.frame.size.width - 50, cell.frame.size.height/2 - 7.5, 15, 15); 
    [cell.contentView addSubview:imgView]; 
    [imgView release]; 

    cell.textLabel.text = @"Location 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%i", aTarget.location]; 
} 
else if (row == 1) { 
    cell.textLabel.text = @"Coordinate"; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", aTarget.coordinate]; 
} 
return cell; 

答えて

1

あなたはUITableViewCellサブクラスを経由して、これを行う必要があり、その後、あなたは、例えばprepareForReuse

で2番目UIImageViewをクリアすることができます

@implementation MyTableViewCellSubclass 


// other methods 
// ... 

- (void)prepareForReuse { 
    [super prepareForReuse]; 

    self.otherImageView.image = nil; 
} 

@end 
関連する問題