Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static cell has background color on iPhone, but not on iPad - can not find the reason

In an iOS 8 project with storyboard and adaptive layout (aka size classes) I use static cells in 2 scenes -

And for some reason the blueish background color of the top cell is not shown on iPad:

screenshots

Please, what could be the reason for that?

I've even searched with debugger (stepped through viewDidLoad) and in XML-code of Main.storyboard - and can not find the cause.

I have reset the simulator settings too and have tried on Yosemite and Mavericks macs that I have.

Here is my storyboard (please click for fullscreen) where I set the background color (for wAny and hAny):

Xcode

In the preview (here fullscreen) the background color is present in both iPad and iPhone:

Preview

If I have done anything wrong here, how to find and reset this?

UPDATE:

I've tried DCGoD's suggestion (thanks) - and it works. When I try setting the cells background color with the following code it works (here fullscreen):

screenshots

#define THEME_COLOR_BLUE [UIColor colorWithRed:19.0/255 green:175.0/255 blue:207.0/255 alpha:1.0]

- (void)tableView:(UITableView *)tableView
    willDisplayCell:(UITableViewCell *)cell
    forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.contentView.backgroundColor = THEME_COLOR_BLUE;
}

And I understand, that I could use this as a workaround...

But I'm still curious what is going wrong with my storyboard. Why does it work for iPhone, but not iPad? I'd prefer to use a pure "visual" solution (makes the storyboard easier to edit).

SOLUTION:

For some strange reason the fix is to set the background color of the "Content View" (and not for its parent - the "Table View Cell". Here fullscreen):

Xcode screenshot

like image 223
Alexander Farber Avatar asked Apr 20 '15 20:04

Alexander Farber


1 Answers

Try changing the background for the cell and then it's contentViews background and you'll discover what's happening.

cell.contentView.backgroundColor = YOURCOLOR

// For static try setting it in willDisplayCell

func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!) {
    cell.contentView.backgroundColor = YOURCOLOR
}
like image 170
Mark McCorkle Avatar answered Oct 21 '22 23:10

Mark McCorkle