0

I'm subscribing an UITableViewCell to an Observer in order to handle changes to that cell (I'm currently doing this at:

tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

Problem I have is as the cell on any kind of reload is then re-subscribed and anytime I do an "onNext" the observer is fired multiple times.

Is there anyway to stop a particular Observer from being subscribed multiple times?

I've attempted to keep a list of Cells that have been subscribed and stop them from re-subscribing - but this seems to cause other issues further down the line (and doesn't feel like the right solution)

MrChrisBarker
  • 141
  • 2
  • 11
  • 1
    I think u need to first unsubscribe and then subscribe in tableView method – SPatel Dec 08 '17 at 09:14
  • Have you tried to clean your DisposeBag? Also check [this](https://stackoverflow.com/questions/39996937/how-to-unsubscribe-from-observable-in-rxswift) – biloshkurskyi.ss Dec 08 '17 at 09:18

1 Answers1

5

Create a DisposeBag in your cell, then attach your subscribe event on it.

Reset the bag in the prepareForReuse.

You can also add a debug() call bedfore the subscribe to check if onComplete is properly called

CZ54
  • 5,488
  • 1
  • 24
  • 39