views:

348

answers:

1

Hi,

when pressing a row delete button on a table view, I do some validation, and if the user chooses to cancel the operation it all should rollback. Not only want to keep that row (what is happening), but also make disappear the delete button leaving only the "-" round button. How can I do that?

once again, thank you.

A: 

Assuming you are implementing your validations in tableView:commitEditingStyle:forRowAtIndexPath: method of your UITableViewDatasource protocol object, you should be able to set the editingAccessoryType and editingAccessoryView on the cell.

//After validation fails....
UITableViewCell *aCell;  
aCell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
// validations are done and you need to ignore the delete
if ( aCell.showingDeleteConfirmation ){
    aCell.editingAccessoryView = nil;
    aCell.editingAccessoryType = UITableViewCellAccessoryNone;

}

If you want, you can wrap the changes in an animation block to animate the change.

Alternatively, you could toggle the editing state of the cell.

//After validation fails....
UITableViewCell *aCell;  
aCell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
if ( aCell.showingDeleteConfirmation ){
    aCell.editing = NO;
    aCell.editingAccessoryView = nil;
    aCell.editing = YES;

}
Chip Coons
Hi Chip,The second solution is the one for me. Works perfectly. The user presses the Delete button; a validation action sheet pops up; the user chooses to cancel delete action; cell turns to initial state. Thank you.
BigJoke