33

Last night I decided to upgrade to Xcode 5 and take a look at my current project. After updating my storyboards to the new UI everything looked great and ran fine. Since I have a universal binary, I decided to test things on iPad as well and noticed that a new white background had been introduced into my UITableview where there once used to be a transparent / clear color. This appears to be happening on the cell level, not the table level. When I run things on the 6.1 simulator everything looks fine on iPad & iPhone. And everything looks fine on iPhone for iOS7.

Everything that I have set up for interface builder is identical for iPhone & iPad. From what I can tell it has something to do with this new "content view" (which is a subgroup of the Item Cell) not honoring a transparent value / setting.

Any thoughts / ideas?

0

4 Answers 4

103

After wasting multiple hours with interface builder, I'm thinking that there might be a bug there. So I started to look for a programatic answer. Apparently had I started here I could have saved a ton of time. By adding to the method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

I was able to solve the transparency issue on iPad by adding this one line:

cell.backgroundColor = [UIColor clearColor];  // Adding this fixes the issue for iPad

Hope this helps everyone else with the white background seen for ipad with tables and iOS7!

10
  • 2
    This was the only solution for me, too. Thanks! (I tried to be cool and set all my cell and content view backgrounds to clear in the XIB, but that only works on first load for some reason (reloadTable will set white backgrounds without your programmatic solution))
    – Rob
    Sep 21, 2013 at 17:10
  • 1
    Definitely is a Xcode 5 bug. I must write cell.backgroundColor = [UIColor clearColor]; as a last instruction inside the method (cellForRowAtIndexPath), because if you change other thing before the instruction in the cell does not work.
    – Beto
    Oct 8, 2013 at 23:55
  • Same exact issue, and this exact resolution solved it for me as well, thanks.
    – Magua
    Mar 7, 2014 at 6:10
  • Take a look at - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    – mcfedr
    Jun 10, 2014 at 14:55
  • 1
    This is still an issue under Xcode 6.0.1. this solution worked just right :)
    – Sobakus
    Oct 1, 2014 at 18:05
4

If you are using a custom UITableViewCell and invoking it from storyboard/xib you can use the following code.

@implementation YourCustomTableViewCell

- (void) awakeFromNib
{
    self.backgroundColor = [UIColor clearColor];
}
3

In case anyone else is still having trouble with table view/cell transparency on iPad, this may help (copied from https://stackoverflow.com/a/31396483/2301213 , it's in swift since the times they are a changin')

It seems that somewhere in the process of adding a UITableView to the window (between willMoveToWindow and didMoveToWindow), some iPad's reset the backgroundColor of the table view to white. It does this covertly without using the backgroundColor property.

I now use this as a base class in place of UITableView when I need a colored/transparent table...

class ColorableTableView : UITableView {
    var _backgroundColor:UIColor?
    override var backgroundColor:UIColor? {
        didSet {
            _backgroundColor = backgroundColor
        }
    }
    override func didMoveToWindow() {
        backgroundColor = _backgroundColor
        super.didMoveToWindow()
    }
}

Cells also have their backgroundColor's set to white on my iPad in the same way (i.e. those that are in the table during the move to the window), so the same applies to them, lest you end up with the odd opaque cell popping up from time to time as it is reused ...

class ColorableTableViewCell : UITableViewCell {
    var _backgroundColor:UIColor?
    override var backgroundColor:UIColor? {
        didSet {
            _backgroundColor = backgroundColor
        }
    }
    override func didMoveToWindow() {
        backgroundColor = _backgroundColor
        super.didMoveToWindow()
    }
}
0
0

If you are using a static cell table. you can do the following:

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

     cell.backgroundColor = UIColor.clearColor()
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.