2

I am new on RxSwift and I am trying to implement UITableView with it. I successfully implemented UITableView cell with rx.items and now I need to use didSelect method.

My problem is; my first cell selection, it called only once and I printed item. But after the first selection tableView.rx.modelSelected called multiple times.

What is the reason for it? How can I prevent from this?

Thanks.

 func showContactListView() {
        UIView.transition(with: self.view, duration: 0.5, options: UIViewAnimationOptions.curveEaseIn,
                          animations: {self.view.addSubview(self.contactSelectionView)}, completion: nil)

       self.selectEmployeeFromList()
    }

    func selectEmployeeFromList() {

        self.contactSelectionView.tableView.rx.modelSelected(Employee.self)
            .subscribe(onNext: { item in

                print(item)
                self.contactSelectionView.removeFromSuperview()



            }).disposed(by: self.disposeBag)


    }
Göktuğ Aral
  • 1,409
  • 1
  • 13
  • 28

1 Answers1

4

Thanks to RxSwift Slack Group,

I was calling showContactListView function everytime. Instead, I need to subscribe to it once elsewhere (i.e. in viewDidLoad or some configuring method). That is all.

But please share your comments if you know alternative patterns.

Göktuğ Aral
  • 1,409
  • 1
  • 13
  • 28