段ちがいで色変えたいときは、UITableViewCellの背景色を、willDisplayCellで変更 2010/03/28

iphoneです。UITableViewの行の色を段違いで変更したいなーと思って、cellForRowAtIndexPathの中でcellにたいして色をつけていたけどかわらず、悩んでました。
で、調べると、実装する箇所がちがっていて、実装する場所は、willDisplayCellのが正しいようです。





以下コード、そのまんまだけど....
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0 || indexPath.row%2 == 0) {
UIColor *altCellColor = [UIColor colorWithWhite:0.7 alpha:0.1];
cell.backgroundColor = altCellColor;
}
}

: