Canceling a delete confirmation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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