テーブルビューの背景を自分の画像でカスタマイズしたい 私は以下のコードを使用してセルの背景ビューをカスタマイズしています
-(void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
NSInteger rowIndex = indexPath.row;
UIImage *background = nil;
if (rowIndex == 0) {
background = [UIImage imageNamed:@"TableTopBackground.png"];
} else if (rowIndex == rowCount - 1) {
background = [UIImage imageNamed:@"TableBottomBackground.png"];
} else {
background = [UIImage imageNamed:@"TableMiddleBackground.png"];
}
[cell setBackgroundView:[[UIImageView alloc]initWithImage:background]];
}
私の問題は、ios5で実行すると下部のセル画像と中央のセル画像が交換されることです(画像1)が、ios6では問題ありませんでした(画像2)。
しかし、背景色を設定すると、ios5とios 6の両方でうまく機能していました。
cellForRowatindexpath にコードを記述しても機能しますが、なぜ willdisplaycell で機能しないのですか。
ありがとうございました