セルをカスタマイズしたUITableViewを作成し、シミュレータで動かしてみると、上下にスクロールして再描画する際に、何の関係もないセルの値が別のセルに再描画されて、文字の上に文字が幾重にも重なり、凄いことになってしまった。それを回避するためには、セル内容作成メソッド cellForRowAtIndexPath で、サブビューを一旦取り除くことで対応できる。
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// ここまでデフォルトのまま。
// サブビューを取り除く
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}