Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I assume you are trying this in cellForRowAtIndexPath.</p> <p>According to the <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html" rel="noreferrer">UITableViewCell class reference</a>:</p> <blockquote> <p>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.</p> </blockquote> <p>So do this:</p> <pre><code>- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor redColor]; //must do here in willDisplayCell cell.textLabel.backgroundColor = [UIColor redColor]; //must do here in willDisplayCell cell.textLabel.textColor = [UIColor yellowColor]; //can do here OR in cellForRowAtIndexPath } </code></pre> <p>If you need finer control over the cell display, an easy way is to design it in IB and load it from the nib in cellForRowAtIndexPath. See the "Loading Custom Table-View Cells From Nib Files" section on <a href="http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW20" rel="noreferrer">this page</a> in the Table View Programming Guide.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload