问题
I added the SWRevealViewController to my app, along with the hamburger stack to access my menu. My app has a UITableView for the main application view. I want to allow users to delete items from the list using the swipe to delete function.
I enabled the swipe to delete and added a method call to handle this. I noticed that the method never gets called. Not sure how to get this to work.
Any help would be greatly appreciated.
I was asked for a code example. I have not made any changes to the SWRevealViewController standard source code. In my code for the TableView, I have added the following:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Normally, the code above should show a delete button when you do a right to left swipe. However, this is not happening. My guess is that the SWRevealViewController is eating the pan gesture recognizer.
回答1:
Just found a solution after reading a thread of a guy asking a similar question to the maker of this class. Whatever class you use to add the gesture recognizers, make it the delegate of the SWRevealController then paste in this method.
#pragma mark - SWRevealViewControllerDelegate
- (BOOL)revealControllerPanGestureShouldBegin:(SWRevealViewController *)revealController
{
float velocity = [revealController.panGestureRecognizer velocityInView:self.view].x;
if (velocity < 0 && self.revealViewController.frontViewPosition == FrontViewPositionLeft)
return NO;
else
return YES;
}
回答2:
I have done like this < UIGestureRecognizerDelegate> in .h file in which you are implementing tableview cell delete functionality and in .m file viewDidLoad
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
self.revealViewController.panGestureRecognizer.delegate = self;
After that simply use this method
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"])
return NO;
else
return YES;
}
来源:https://stackoverflow.com/questions/25319940/swrevealviewcontroller-and-tableview-swipe-to-delete-not-working