Enable UITableViewCell swipe-to-delete in the center view controller without edit button
Hello,
While trying to implement this library with swipe-to-delete in UITableViewControllers I noticed that there are issues with the swipe gesture and showing the MMDrawerController. Currently the library has a workaround disabling the gesture once the UITableViewController is set to Edit mode.
I found a way to implement it even if the UITableViewController doesn't have a button to set it into Edite mode. Basically it would need a new condition in the possibleOpenGestureModesForGestureRecognizer: method within MMDrawerController class.
The code condition would be:
if ([[touch.view.class description] isEqualToString:@"UITableViewCellContentView"]) {
possibleOpenGestureModes = MMOpenDrawerGestureModeNone;
}
And implemented it would look like this:
-(MMOpenDrawerGestureMode)possibleOpenGestureModesForGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer withTouch:(UITouch*)touch{
CGPoint point = [touch locationInView:self.childControllerContainerView];
MMOpenDrawerGestureMode possibleOpenGestureModes = MMOpenDrawerGestureModeNone;
// This new condition will disallow to show the menu when swiping over UITableViewCells.
if ([[touch.view.class description] isEqualToString:@"UITableViewCellContentView"]) {
possibleOpenGestureModes = MMOpenDrawerGestureModeNone;
} else if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]){
if([self isPointContainedWithinNavigationRect:point]){
possibleOpenGestureModes |= MMOpenDrawerGestureModePanningNavigationBar;
}
if([self isPointContainedWithinCenterViewContentRect:point]){
possibleOpenGestureModes |= MMOpenDrawerGestureModePanningCenterView;
}
if([self isPointContainedWithinLeftBezelRect:point] &&
self.leftDrawerViewController){
possibleOpenGestureModes |= MMOpenDrawerGestureModeBezelPanningCenterView;
}
if([self isPointContainedWithinRightBezelRect:point] &&
self.rightDrawerViewController){
possibleOpenGestureModes |= MMOpenDrawerGestureModeBezelPanningCenterView;
}
}
if((self.openDrawerGestureModeMask & MMOpenDrawerGestureModeCustom) > 0 &&
self.gestureShouldRecognizeTouch){
if(self.gestureShouldRecognizeTouch(self,gestureRecognizer,touch)){
possibleOpenGestureModes |= MMOpenDrawerGestureModeCustom;
}
}
return possibleOpenGestureModes;
}
I hope this solution would work for someone with the same issue.
Best regards,
I'm torn on what the default behavior should be here.
If we go this way, then it would not be possible to have a bezel gesture open and also support swiping table view cells.
We do provide the block setGestureShouldRecognizeTouchBlock where you could easily provide this behavior for your own needs.
Been really struggling with the best default option here.
Thank you @acubillo
I updated the code as you suggested and it work very well.
setGestureShouldRecognizeTouchBlock didn't work for me.
Hi all. I have the same problem with last version. I can't disable drawer swiping with the table view cell to enable edit mode. So, I changed 'possibleOpenGestureModesForGestureRecognizer:withTouch:' method of MMDrawerController and my changes is: Was:
if((self.openDrawerGestureModeMask & MMOpenDrawerGestureModeCustom) > 0 &&
self.gestureShouldRecognizeTouch){
if(self.gestureShouldRecognizeTouch(self,gestureRecognizer,touch)){
possibleOpenGestureModes |= MMOpenDrawerGestureModeCustom;
}
}
Become:
if(self.gestureShouldRecognizeTouch){
if(self.gestureShouldRecognizeTouch(self,gestureRecognizer,touch)){
possibleOpenGestureModes |= MMOpenDrawerGestureModeCustom;
} else {
possibleOpenGestureModes = MMOpenDrawerGestureModeNone;
}
}
Hope this will be helpful.