How to determine if UItableviewcell's delete button is hidden?

I have a view containing a UITableView. I can show the delete button in the cell when the user searches.

If the user touches the delete button, the method will be launched (this works great). But if the user decides not to delete the cell, and he touches any point of view to hide the delete button.

How can I detect this?

+5
source share
3 answers

When a user deletes a delete mark in a cell, your program should receive a call tableView:didEndEditingRowAtIndexPath:in the table view delegate.

+3
source

[UITableViewCell showingDeleteConfirmation]

or

[UITableViewCell willTransitionToState:]with UITableViewCellStateShowingDeleteConfirmationMaskas parameter

+3
source

Your subclass of UITableViewCell implements the willTransitionToState: method. This method is called by UITableView when the cell goes to / from the editing state.

In your implementation of the class, you will need to conditionally check the value of the mask parameter passed to the method to determine what state the cell translates to / from. Possible values ​​for the mask ...

enum {
    UITableViewCellStateDefaultMask                     = 0,
    UITableViewCellStateShowingEditControlMask          = 1 << 0,
    UITableViewCellStateShowingDeleteConfirmationMask   = 1 << 1
};

In your case, you will need transition observations in the UITableViewCellStateDefaultMask, so your implementation will be as follows:

- (void)willTransitionToState:(UITableViewCellStateMask)state {
    if (state == UITableViewCellStateDefaultMask) {
        // User has switched back to default state...
        // ...
    }
}
+1
source

All Articles