2016-10-06 16 views
1

現在、View Controller内のtableViewに編集機能を追加しようとしています。
このView Controllerは、MapView(Mapbox)である親ViewControllerの上に追加されます。ジェスチャーに反応しませんUITableVIew editActionsForRow

現在、私は問題なしで垂直スクロールでtableViewを上下にスクロールできます。
しかし、TableViewCellでアクションを呼び出すために水平方向にスワイプすると、マップビューはその位置をスクロールします。
私は、マップビューのスクロールジェスチャーを無視するためにしばらく見つけることができません。
マップのスクロールを無効にしても問題は解決されません。テーブルビューの編集コード:

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] 
} 

とのUIViewControllerはのMapViewの上にテーブルビューを含む追加機能:

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 
} 
+0

私は自分のアプリで(これは私をもたらした)同様の問題に気付きました。私が知ることから、スワイプの「編集開始」トリガは非常に矛盾しています。画面/テーブルの右端からスワイプを開始すると、私は一番の運があります。私はraywenderlichの記事で、表のセルをスワイプすることについて調べてきましたが、UITableViewRowActionによって廃止されていると主張しています。より良い解決策を見つける運が良かった! – Lytic

答えて

1

[OK]を、私は一緒に私を解決するように見えた組み合わせ、いくつかの異なる答えをつなぎ合わせています問題。

まず:

、編集委譲が設定されていることを確認 - 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 
+0

あなたの実装を使用しようとしましたが、それでも失敗しました。しかし、助けてくれてありがとう。私は[MGSwipeTableCell](https://github.com/MortimerGoro/MGSwipeTableCell)を使用して終了し、問題なく動作します。 –

+0

私もMGSwipeTableCellを使用しようとしていましたが、UITableViewから上記のUIViewを編集して修正したようです!明らかに、ビュー階層内の任意のジェスチャ認識機能は、スワイプを傍受してアクションを削除することができます。あなたがそれを働かせてくれてうれしく、担当者に感謝しています! – Lytic

関連する問題