ios - 不响应手势 UITableVIew editActionsForRow

标签 ios swift uitableview mapbox

我目前正在尝试向 View Controller 内的 tableView 添加编辑功能。
此 View Controller 添加在父 ViewController 之上,它是 MapView (Mapbox)。

目前,我可以通过垂直滚动向上和向下滚动 tableView,没有任何问题。
但是,水平滑动以在 TableViewCell 上显示操作会导致 mapview 滚动其位置。
我不能花点时间忽略 map View 的滚动手势。
禁用 map 滚动也不能解决问题。 TableView 编辑代码:

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    //
}

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let test1 = UITableViewRowAction(style: .normal, title: "Test1") { (_, indexPath) in

    }

    test1 = UIColor=.red

    let test2 = UITableViewRowAction(style: .normal, title: "Test2") { (_, indexPath) in

    }

    test2 = UIColor.blue

    return [test1, test2]
}

以及在 Mapview 之上添加包含 TableView 的 UIViewController 的函数:

self.detailView = UIView(frame: CGRect(x: 0, y: self.view.bounds.height,    width: self.view.bounds.width, height: self.view.bounds.height))
self.view.addSubview(self.detailView!)
self.detailViewController = TestViewController()

self.detailViewController!.view.frame = self.view.bounds
self.detailView?.addSubview(self.detailViewController!.view)
self.addChildViewController(self.detailViewController!)

UIView.animate(withDuration: 1.0) {
     self.detailView?.frame = self.view.bounds
}

最佳答案

好的,我拼凑了几个不同的答案,这些答案结合起来似乎可以解决我的问题。

首先:

确保您的编辑委托(delegate)已配置 - 注意 editingStyleForRow 的差异

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    // handle your data source changes here
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    // This is important, as the editing behavior changes the editing style for some reason?

    return tableView.isEditing ? UITableViewCellEditingStyleNone: UITableViewCellEditingStyleDelete;
}

-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

第二个:

确保您的手势不被拦截。我将这个类别添加到托管 UITableView 的 UIViewController 中:

@interface UIView (CellSwipeAdditions)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
@end

@implementation UIView (CellSwipeAdditions)
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
        return YES;
    }
@end

关于ios - 不响应手势 UITableVIew editActionsForRow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39902052/

相关文章:

ios - Swift - Firebase 如何在没有父项的情况下仅获取子项值

javascript - 带有 Cordova 的 iPhone 上的位置权限警报

swift - 为什么不能为 Measurement<UnitMass> 变量赋值?

ios - 使用自己的 Nib 子类化 UITableViewCell

ios - UITableViewCell 中的 Swift WebKitView - Cell 每次出现在屏幕上时都会重新加载 webkit View

ios - 如何在应用程序中打开 youtube 视频?

ios - UISplitview Controller 在 iOS 4.3 和 5.x 中不旋转。它在 iOS 6.0 上运行良好

ios - Swift - 函数完成后如何调用函数?

xcode - 检测应用程序是否打开 x 次

ios - 为什么我的 UITableViewCell 子类中没有调用 layoutSubViews?