views:

2749

answers:

2

Is it possible to change the view shown in response to a left to right "I want to delete this row" swipe in a UITableView's UITableViewCell?

Currently the 'delete' button seems to ignore all of the other UITableViewCell customisation options.

+5  A: 

The tricky thing about deleting cells is this: when you swipe left to right to show the "delete" button, the UITableViewCell moves to the UITableViewCellStateShowingDeleteConfirmationMask state, but doesn't set its UITableViewCellStateEditingMask state. This means you can't change the accessoryView for the editing state.

The way to get around this is to look at the willTransitionToState: method of UITableViewCell. What you can do is intercept the call to this method that would put your cell in the delete confirmation state and show your own views instead of the "Delete" confirmation button that normally gets shown.

For more info, look at the docs for willTransitionToState: for UITableViewCell. (Requires registration as Apple developer.)

Tim
Thanks Tim. That lets me intercept the swipe to get into editing mode but it's not clear to me how to stop the UITableViewCell displaying its own 'delete' button. Currently this happens when I pass the message on to super - which the documentation says is mandatory.Are you also proposing that the only way to do this is to add my own UIButton and do the delete wiring myself rather than relying on the dataSource's tableView:commitEditingStyle:forRowAtIndexPath:?It seems weird that the delete handling bypasses all of the UITableViewCell customisation options.
Roger Nolan
Hm. I'm not quite sure it's possible to completely suppress the display of the UITableViewCell's built-in Delete button, unless you do as you suggested and set up your own delete button in lieu of calling the super method.You could perhaps intercept willTransitionToState: messages that place it in Delete mode and reroute them to place the table in editing mode, which (IIRC) provides a delete control as well (the small red minus symbol).
Tim
That sounds dodgy. I think for now I'll work around the Apple button and if I have time implement my own swipe detection and delete control.
Roger Nolan
Did you manage to do it?
Pumbaa80
A: 

Apparently not. This is a known defect as of the time of writing. Original defect report is radar id 6075403

Roger Nolan