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?
Asked
Active
Viewed 1.0k times
8
-
It may be helped you- https://www.raywenderlich.com/138547/getting-started-with-rxswift-and-rxcocoa – iDeveloper Mar 30 '17 at 11:27
-
Thanks, but I need more precise answer. – Mehreen Mar 30 '17 at 12:18
-
Hi Mehreen, Is your issue resolved ? – iDeveloper Mar 31 '17 at 04:32
-
Yes. It has been resolved. – Mehreen Mar 31 '17 at 06:40
-
Great , Enjoy coding... – iDeveloper Mar 31 '17 at 06:49
-
Thanks for responding.. – Mehreen Mar 31 '17 at 07:11
2 Answers
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
-
Thanks, I did it the same way. It works quite fine. My concern is that whether there is another way to perform the same task? – Mehreen Mar 30 '17 at 12:20
-
No, there is not, just the same task for `UITableViewDataSource` – Twitter khuong291 Mar 30 '17 at 12:53
-
May I know what is the difference between `tableView.delegate = self` and using rx to set the delegate? – Ryan Dec 31 '19 at 03:39
-
-
tableView.rx.setDelegate requires UIScrollViewDelegate as a parameter. – Darius Miliauskas Dec 07 '21 at 17:35