2012年3月12日月曜日

UITableViewCellの背景色変更


UITableViewCellの背景色を変更するにはtableView:willDisplayCell:forRowAtIndexPath:をオーバライドし、backgroundColorを設定します。
これをtableView:cellForRowAtIndexPath:で行っても反映しません。リファレンスに書いてありますが、わざわざ書いてあるということは、これで悩まされる人が多いからでしょう。

UITableViewCell Class Reference

Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source.

0 件のコメント: