Alex Rivera | Logout

Why doesn't UITableViewCell background color work (set in interface builder)?

Asked 2011-03-02T11:20:51.373
58

Why doesn't UITableViewCell background color work (set in interface builder)?

I note from some searching that the follow code set in your custom subclass of UITableViewController does work (see below):

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor redColor];
}

But I would still like to just understand why interface builder has a background color setting for the TableViewCell, which effectively doesn't seem to work?

Edit
Report

1 Answer

11

Trying to set the background colour of the UITableViewCell itself is not how you should be doing it. A table cell has a collection of five useful views you can access, one of which is backgroundView.

Recommended reading:

http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

and then:

http://cocoawithlove.com/2010/12/uitableview-construction-drawing-and.html

answered 2011-03-02T12:06:40.927

Your Answer