不响应手势 UITableVIew editActionsForRow
Not responding gestures UITableVIew editActionsForRow
我目前正在尝试向视图控制器内的 tableView 添加编辑功能。
此视图控制器添加在父级 ViewController 之上,它是一个 MapView (Mapbox)。
目前,我可以通过垂直滚动向上和向下滚动 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
}
好的,我拼凑了几个不同的答案,这些答案结合起来似乎解决了我的问题。
第一个:
确保您的编辑委托已配置 - 请注意 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
我目前正在尝试向视图控制器内的 tableView 添加编辑功能。
此视图控制器添加在父级 ViewController 之上,它是一个 MapView (Mapbox)。
目前,我可以通过垂直滚动向上和向下滚动 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
}
好的,我拼凑了几个不同的答案,这些答案结合起来似乎解决了我的问题。
第一个:
确保您的编辑委托已配置 - 请注意 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