8

I am using RxSwift for TableView.I need to calculate height of dynamic cells previously I did it in WillDisplayCell delegate method. I don't know how to bind TableView Delegate methods with RxSwift. Can any one help?

Mehreen
  • 501
  • 3
  • 6
  • 11

2 Answers2

24

Actually you can. Try this:

       tableView.rx
        .willDisplayCell
        .subscribe(onNext: { cell, indexPath in
   //Do your will display logic
           })
        .disposed(by: disposeBag)
Aaqib Hussain
  • 828
  • 2
  • 9
  • 12
  • Can you please elaborate your answer for others. Most of the times, you shall answer, what was the problem, why this fix works, etc. – ankitjaininfo Jun 28 '18 at 17:08
  • @ankitjaininfo The question was about how to bind TableViewDelegate methods using Rx, this is one example I wrote for the willDisplayCell delegate method, similarly can be done for the other methods. – Aaqib Hussain Jun 28 '18 at 17:59
  • I didn't know we can use WillDisplay Cell method like this way thanks... – Leena Aug 23 '18 at 08:41
11

Conform your View Controller

class YourViewController: UIViewController, UITableViewDelegate

Then add this in viewDidLoad()

tableView.rx.setDelegate(self).addDisposableTo(disposeBag)

then you write UITableViewDelegate methods.

Twitter khuong291
  • 11,328
  • 15
  • 80
  • 116