简体   繁体   中英

Observer still receiving events after being disposed in cell RxSwift

I'm using RxSwift for form handling in collection view and table view. I am facing an issue.

I have a single selection list component and I am creating DisposeBag every time while configuring to remove all previous subscribers. onDisposed method is called for both but I still receive duplicate onNext events. This works fine in that start but when I reload the collection view or the table view I am facing this issue. Please let me know is there something I am doing wrong or is this bug in library.

var selectedIndex = Variable<Int?>(nil)

func configureRx(sender: RxRow<Int>) {

    dateVarDisposable = DisposeBag()

    selectedIndex
        .asObservable()
        .subscribe(onNext: {[weak self] (index) in
            self?.selectRow(selectedIndex: index)
            }, onDisposed: {

                print("")
        })
        .addDisposableTo(disposableBag)

    sender.dataVariable.asObservable()
        .debug(self.stringTag, trimOutput: false)
        .subscribe(onNext: { (sender) in
            self.selectedIndex.value = sender
        }, onDisposed: {
    })
        .addDisposableTo(disposableBag)        
}

Check this: https://github.com/ReactiveX/RxSwift/issues/821 . There's a special category for cells - reuseBag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM