Objective-c – Changing background color of a custom UITableViewCell cell in a plain styled UITableView

cocoa-touchiphoneobjective cuitableview

I am trying to change the background color of a custom UITableViewCell in a plain style UITableView.

I've read the other similar questions, and I in my delegate method:

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath

I set cell.backgroundColor = [UIColor...]. The problem is this only works for a grouped style UITableView.

Note: The reason why I want to do this programmatically and not in my .xib file is because I want different background colors for different cells.

Best Answer

Maybe you can add cell.contentView.backgroundColor = [UIColor clearColor] before you set your color.

The reason is that the backgroundview is at the bottom. The contentview is at the top.