UITableViewのCellは、メモリ効率よく管理するためにスクロールして完全に消えると、次に出現するセルに対して、その消えたセルが再利用される。その結果、「tableView.imageView.image」でユニークな画像を定義していると、それがそのまま使用され、不都合な場合がある。
以下、対処法。要は、セルの複製を無効にしている。大量のセルを使用する場合は、別の方法を検討したほうがいい。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
↓
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
//}
#pragma unused(cell)
// Configure the cell...
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
「#pragma unused(cell)」を入れないと、Build And Analyze でエラーがでる。
コメントする