Ios – UITableView with static cells without cellForRowAtIndexPath. How to set clear background

cocoa-touchiosuitableviewxcode

I have a static UITableView and everything is laid out on the Storyboard. In cellForRowAtIndexPath i simply use

return [super tableView:tableView cellForRowAtIndexPath:indexPath];

and the tableview works great. However I want to set the cells backgrounds to [UIColor clearColor]
How can I do this? The table has 30 cells, each one different.

Thanks

Best Answer

I'm not entirely sure if this will work, because I've never tried using super to manage the cells. If your code works with super, then you should be able to get away with doing this to set the background color:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}

Either way, this seems to me like a strange way of doing things. Normally the cells are created and reused in the method itself, as per the default UITableView boiletplate code, without calling super.

Related Topic