SWRevealViewController和TableView - 滑动删除不起作用 [英] SWRevealViewController and TableView - swipe to delete not working
问题描述
我将SWRevealViewController添加到我的应用程序,以及汉堡包堆栈来访问我的菜单。我的应用程序有一个UITableView用于主应用程序视图。我想允许用户使用滑动删除功能从列表中删除项目。
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.
我被要求一个代码示例。我没有对SWRevealViewController标准源代码进行任何更改。在我的TableView代码中,我添加了以下内容:
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];
}
}
通常,上面的代码应显示删除按钮你做左右滑动。但是,这种情况并没有发生。我的猜测是SWRevealViewController正在吃平底锅手势识别器。
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.
推荐答案
刚刚在阅读了一个问题的线程后找到了一个解决方案这个类的制造者也有类似的问题。无论您使用哪个类来添加手势识别器,都可以将其作为SWRevealController的委托,然后粘贴到此方法中。
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;
}
这篇关于SWRevealViewController和TableView - 滑动删除不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!