Reputation: 7525
I am trying to create a table with an image as a background. To achieve this, I started out with the background:
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
This resulted in a background image which appears in tablecells as well. That is not something I want, so I tried to set the cell's backgroundColor:
cell.backgroundColor = [UIColor whiteColor];
This had no effect at all !!!. Hmmm strange. So I tried this:
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = backgroundView;
[backgroundView release];
This works almost. The only problem left is that the textLabel & the detailTextLabel still show the background behind them. Setting the backgroundColor on those labels to white doesn't do anything either.
How do I proceed? Where do I go wrong? I am trying to achieve a tableView like the worldClock app has.
Upvotes: 2
Views: 842
Reputation: 1881
To change the background colour of the table view cell, you'll need to set it in tableView:willDisplayCell:forRowAtIndexPath:
rather than tableView:cellForRowAtIndexPath:
otherwise it won't have any effect, for example:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor whiteColor];
}
Upvotes: 10