Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 619
Darren Avatar asked Aug 16 '12 19:08

Darren


2 Answers

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.

like image 148
Jonathan Ellis Avatar answered Sep 28 '22 01:09

Jonathan Ellis


Try this delegate method:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {  cell.backgroundColor = [UIColor clearColor]; } 
like image 28
CSmith Avatar answered Sep 28 '22 01:09

CSmith