views:

26

answers:

1

I'm trying to set the background color on a cell. It works fine in iOS 4 on a 3GS and in the sim, but when I test in 3.2 I get a background on the text label that I can't get rid of.

alt text

I've tried to set the opacity and background of the label, detail label, content view, and accessory views manually and had no success. I even resorted to the following to make sure I "got everything" (though I don't know what else there would be...).

void setBackgroundColor (UIView *view, UIColor *color) {
    view.opaque = NO;
    view.backgroundColor = color;
    for (UIView *subview in [view subviews]) {
        setBackgroundColor(subview, color);
    }
}
...
setBackgroundColor(cell, [UIColor blueColor]);

So, what could cause this on the iPad but not on the iPhone?

A: 

It turns out that you can't set the background in cellForIndexPath and have to do it in:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

Now it works perfectly.

codepoet