2017-07-28 12 views
0

私はRxSwiftについて質問します。
私はRxSwift
でのtableViewデリゲートの機能を使用したいとき、私は
..私は問題の原因を知っていない問題を抱えて、私はrx.ItemSelectedとセルに選択しないときに問題がある、私が得ましたセルの位置およびイベントを最初にうまくトリガします。
私が行うイベントはpushViewControllerで、前のビューに戻ったときです。その後、同じセルで再びタップします。セルが2回トリガーされ、同じことをすると、1 - > 2 - > 3 - > n + 1のようにトリガーされます。
これを修正するには? 私のコードの一部です:Rx ItemSelectedは、トリガされたアクションの量に依存します。

root.tableView.rx.itemSelected.subscribe(onNext: { index in 
    switch index.row : 
    case 0 : 
    DSource.navbar?.pushViewController(nextViewController, animated: true) 
    case 1: 
    Source.navbar?.pushViewController(secondViewController, animated: true) 
    default : 
    break 

} 
+1

このコードはどの方法ですか? 'disposeBag'はありますか?あなたの 'ViewController'が現れるたびにサブスクリプションが作成されているようです。 – XFreire

答えて

0

サブスクリプションを削除するにはdisposableBagを追加してください。

let disposeBag = DisposeBag() 

     root.tableView.rx.itemSelected.subscribe(onNext: { index in 
      switch index.row 
      case 0: DSource.navbar?.pushViewController(nextViewController, animated: true) 
      case 1: Source.navbar?.pushViewController(secondViewController, animated: true) 
      default : break 
     }).addDisposableTo(disposeBag) 
関連する問題