I currently have a UITableView set up to enable swipe-to-delete (a swipe shows the Delete button). I also have an Edit button which, when pushed, slides in the red deletion circles for each cell. Tapping one of those circles causes the Delete button to show as if I'd swiped the cell.
I'd like to detect whether the Delete button was created via one of the red circles (i.e. in Edit mode) or by directly swiping on the cell (reason being I'd like the user to confirm if they didn't come in via Edit mode, since they can potentially lose a lot of data if they mistapped it).
I've tried the isEditing
property of the tableView, but that's YES
however I got to the delete button. Is there a more nuanced way to detect this?
Thanks in advance!
The much simpler approach is to use the UITableView
delegate support to know when you are about to enter single row editing. The tableView:willBeginEditingRowAtIndexPath:
delegate call occurs BEFORE calling setEditing:animated:
which allows you to avoid any normal edit setup such as creating an insert row, etc. The tableView:willEndEditingRowAtIndexPath:
is called AFTER setEditing:animated.
So the code is as simple as:
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
self.singleRowDeleteMode = YES;
}
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
self.singleRowDeleteMode = NO;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
if (self.singleRowDeleteMode) { return; }
// Continue setup of normal edit mode
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With