Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView delete editing pushes cell content to the right

When setting [self.tableView setEditing:TRUE]; on a tableView the native table delete editing icons appear to the left. But when using a plain styled table these round icons pushes my row background (and content) to the right.

How can I prevent the editing style from changing my cell position, and instead put the icon on top off the cell?

The way it is now it looks like a bug.

Another question on this. Is there some way to define indexPath.row == 0 to not have an delete icon on setEditing:TRUE?

like image 804
doh Avatar asked Feb 22 '11 08:02

doh


2 Answers

  1. Set cell's shouldIndentWhileEditing property to NO.
  2. Implement delegate's tableView:editingStyleForRowAtIndexPath: method and return appropriate value from it, e.g.:

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
       if (indexPath.row == 0)
           return UITableViewCellEditingStyleNone;
       return UITableViewCellEditingStyleDelete;
    }
    
like image 68
Vladimir Avatar answered Nov 04 '22 20:11

Vladimir


Ok, found why #1 was not working. I hade set my row background as a view on cell.contentView, in stead of putting it on cell.backgroundView. This way the built in functionality could not separate background from content.

The shouldIndentWhileEditingRowAtIndexPath function will only prevent background from indenting, and not content, as there has to be room for the editing icon.

like image 23
doh Avatar answered Nov 04 '22 20:11

doh