Last Updated: February 20, 2016
·
1.596K
· markrickert

Change the background of a UITableView on the iPad

For some reason, the iPad version of a UITableView doesn't respond to this:

self.tableView.backgroundColor = [UIColor redColor];

Run it on an iPhone and the table background will be red. Run it on an iPad and the background property will not have changed.

Here's how to get around this:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    [self.tableView setBackgroundView:nil];
    [self.tableView setBackgroundView:[[UIView alloc] init]];
}
self.tableView.backgroundColor = [UIColor redColor];