【问题标题】:Not responding gestures UITableVIew editActionsForRow不响应手势 UITableVIew editActionsForRow
【发布时间】:2016-10-06 17:17:02
【问题描述】:

我目前正在尝试将编辑功能添加到视图控制器内的 tableView。
此视图控制器添加在作为 MapView (Mapbox) 的父 ViewController 之上。

目前,我可以使用垂直滚动上下滚动 tableView 没有任何问题。
但是,水平滑动以在 TableViewCell 上显示操作会导致 mapview 滚动其位置。
我找不到同时忽略地图视图的滚动手势。
禁用地图滚动也不能解决问题。 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
}

【问题讨论】:

  • 我在我自己的应用程序中注意到了一个类似的问题(它把我带到了这里)。据我所知,滑动的“开始编辑”触发器非常不一致。从屏幕/表格单元的最右边缘开始滑动时,我的运气最好。我查看了 raywenderlich 关于滑动表格单元格的文章,但他们声称 UITableViewRowAction 已弃用它,您和我都同意它的默认形式是不够的。祝你好运找到更好的解决方案!

标签: ios swift uitableview mapbox


【解决方案1】:

好的,我拼凑了几个不同的答案,它们似乎可以解决我的问题。

第一:

确保您的编辑代理已配置 - 请注意 editorStyleForRow 的差异

- (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;
}

第二:

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

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

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

【讨论】:

  • 我也尝试使用您的实现,但仍然不成功。谢谢你的帮助。我最终使用了MGSwipeTableCell,它没有问题。
  • 我也正要使用MGSwipeTableCell,然后我从UITableView 到UIView 进行了上面的编辑,它似乎已经修复了它!显然,视图层次结构中任何位置的任何手势识别器都可以拦截并阻止滑动删除操作。很高兴您成功了,感谢您的代表!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-01
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
相关资源
最近更新 更多