UITableViewCell custom edit view

ios, objective-c, uikit, uitableview

Solution

Your problem is that UITableView is "helpfully" setting up the appropriate state layout with the cell you return from cellForRowAtIndexPath.

Simplest way to deal with this is to override -layoutSubviews in your cell class.

- (void)layoutSubviews
{
   if (self.editing)
  {
     CGRect bounds = self.bounds;
     // do your custom layout
  }
  else
    [super layoutSubviews];
}

That should get things pretty much sorted.

Problem

I am trying to replace the default editing mode behaviour of the cells. I dont want the red circle with line left accessory view to appear. Upon entering edit mode I need it to shift the content view left & display my delete button. What I have so far (custom UITableViewCell) overrides: ``` -(void) setEditing:(BOOL)editing animated:(BOOL)animated { /* don't call super */ // [super setEditing:editing animated:animated]; _isEditing = editing; CGFloat newContentViewX = 0.0f; UIColor *newDeleteButtonColor = [UIColor clearColor]; if ( _isEditing ) { newContentViewX = -40.0f; newDeleteButtonColor = [UIColor redColor]; } if ( animated ) { [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^ { self.contentView.x = newContentViewX; //change frame.origin.x _deleteButton.backgroundColor = newDeleteButtonColor; } completion:nil]; } else { self.contentView.x = newContentViewX; //change frame.origin.x _deleteButton.backgroundColor = newDeleteButtonColor; } } -(BOOL) editing { return _isEditing; } ``` & this is the result: The above code works great! Until it starts scrolling & the contentview gets reset. back to the first image. The editing flag is not persisting my contentview frame changes. I have added this line: ``` [cell setEditing:_tableView.isEditing animated:NO]; ``` in cellForRowAtIndexPath & although it is calling & setting edit mode correctly my contentview is still in the original position & not the updated Short youtube video explaining issue: Youtube link Anyone else had this problem?

Original source