Search code examples
iosswiftuitableviewrx-swiftrx-cocoa

TableView made with RxSwift/RxCocoa glitches after a data change in the Variable it's bound to


The tableView that my variable is bound to jumps/glitches when the cell that I clicked on to trigger the data change.

Here is how the tableView and variable are bound:

variable.asObservable()
        .bind(to: tableView.rx.items)
            { (tableView, row, dataForRow) in

}

When one of the buttons in the tableView is pressed I eventually update the variable's value like this:

variable.value = updatedData

Does anyone know why this would be happening?

Any help would be appreciated.

Thanks in advance.


Solution

  • To fix the issue you have to assign a new instance of DisposeBag to the cell's disposeBag variable when prepareForReuse() is called:

    class CustomCell: UITableViewCell{
    
    var disposeBag = DisposeBag() 
    
    
    override func prepareForReuse() {
            super.prepareForReuse()
    
            disposeBag = DisposeBag() 
        }
    }