Skip to content

Instantly share code, notes, and snippets.

@heydona

heydona/gist:4569311

Last active Dec 11, 2015
Embed
What would you like to do?
Canceling a delete confirmation
- (void)willTransitionToState:(UITableViewCellStateMask)state {
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
// ...
_showingConfirmation = YES;
_cancelDeleteGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteConfirmation:)];
[_table addGestureRecognizer:_cancelDeleteGesture];
} else {
// ...
}
// ...
}
- (void)didTransitionToState:(UITableViewCellStateMask)state {
if (_showingConfirmation) {
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) != UITableViewCellStateShowingDeleteConfirmationMask) {
_showingConfirmation = NO;
if (_cancelDeleteGesture) {
[_table removeGestureRecognizer:_cancelDeleteGesture];
_cancelDeleteGesture = nil;
}
}
}
[super didTransitionToState:state];
}
// In iOS5 the tap gesture is fired before the touch on the delete button, even though the highlight happens
// In iOS6 the touch on the button fires before the tap gesture
- (void)deleteConfirmation:(UITapGestureRecognizer *)sender {
if ([sender state] == UIGestureRecognizerStateEnded) {
UITableViewCellEditingStyle editStyle = UITableViewCellEditingStyleNone;
// Determine if we actually tapped on the delete button
CGPoint curLocation = [sender locationInView:self];
if (CGRectContainsPoint([_deleteButton frame], curLocation)) {
_isDeleting = YES;
editStyle = UITableViewCellEditingStyleDelete;
}
[self commitEdit:editStyle];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment