UITableView clear background

I realize that iOS 7 has not officially been released and we should not discuss it BUT I am going crazy trying to figure out this problem. On iOS 6, my table view was transparent and looked great. First time running iOS 7, and the background is white.

I have tried making the table backgroundColor, cell color etc etc to UIColor clearColor but have no change.

How to fix this problem?

the table


    // Fix for iOS 7 to clear backgroundColor
    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView = [[UIView new] autorelease];
    cell.selectedBackgroundView = [[UIView new] autorelease];

in cellForRowAtIndexPath

Also, make sure that your tableview actually has transparent background (in storyboard): enter image description here


Put this:

cell.backgroundColor = [UIColor clearColor];

In this section:

cellForRowAtIndexPath

Try setting backgroundView to nil first.

[self.tableView setBackgroundView:nil];
[self.tableView setBackgroundColor:[UIColor clearColor]];

Not sure if this is a change in documentation with iOS7 or has always been there and just did not affect background color, but per UITableView Class Reference @property backgroundView

"You must set this property to nil to set the background color of the table view."

edit: corrected code syntax


This has been answered, but incorrectly in a lot of ways.

You need to implement the below delegate method:

    - (void)tableView:(UITableView *)tableView  willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}

You can't put the fix in cellForRowAtIndexPath because that is after the cell is rendered, and it will flash a white background before the background gets set to clear (on slower devices).

Use this delegate method and your problems are solved!


Actually the officially correct place to change cell background color is different according to documentation (UITableViewCell Class Reference):

Whether you use a predefined or custom cell, you can change the cell’s background using the backgroundView property or by changing the inherited backgroundColor property. In iOS 7, cells have a white background by default; in earlier versions of iOS, cells inherit the background color of the enclosing table view. If you want to change the background color of a cell, do so in the tableView:willDisplayCell:forRowAtIndexPath: method of your table view delegate.