Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintain UITableViewCell background color when going into edit mode

I have set background colors for all my UITableViewCells. However, when I click my UIBarButtonItem "edit", the delete and the draggable icons distort the background color, making white background behind them. Is there any way around this? I can show code if necessary, but this seems like a pretty straightforward question.

like image 816
Mason Avatar asked Dec 07 '22 20:12

Mason


2 Answers

The background color of a table cell is usually set like this:

cell.backgroundView.backgroundColor = [UIColor redColor];

This works fine. However, when an object of class UITableViewCell is created, by default it does not have a backgroundView, it is nil. The developer needs to create the backgroundView when needed. So depending on the particular situation you need to do something like:

if (cell.backgroundView == nil) {
  cell.backgroundView = [[[UIView alloc] init] autorelease];
}
cell.backgroundView.backgroundColor = [UIColor redColor];
like image 84
Roelof Avatar answered Dec 09 '22 09:12

Roelof


This is the default behavior of the uitableviewcells in the editing mode. Try setting the background color for your tableViewCells again in

 - (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
if(editing)
{
  // set background color
}

else {
}

If needed, try setting your background color as your property so that you can set it up here.

like image 37
Legolas Avatar answered Dec 09 '22 10:12

Legolas