简体   繁体   中英

How to use RxSwift with NVActivityIndicatorView?

I'm trying to use NVActivityIndicatorView with RxSwift and MVVM . I'm extending NVActivityIndicatorView like below :

extension Reactive where Base: NVActivityIndicatorView {

/// Bindable sink for `startAnimating()`, `stopAnimating()` methods.
public var isAnimating: Binder<Bool> {
    return Binder(self.base) { activityIndicator, active in
        if active {
            activityIndicator.startAnimating()
        } else {
            activityIndicator.stopAnimating()
        }
    }
}}

And binding data like this:

splashVM.loading.bind(to: NVActivityIndicatorView.rx.isAnimating).disposed(by: disposeBag)

but i get tis error :

Instance member 'isAnimating' cannot be used on type 'Reactive<NVActivityIndicatorView>'

if I set isAnimation static ,that error goes away but another error pops up :

Instance member 'base' cannot be used on type 'Reactive<Base>'

what's the problem exactly? what should i change?

You are binding it wrong. You need to bind to a specific activity indicator view not the class:

let activityIndicatorView: NVActivityIndicatorView

splashVM.loading
    .bind(to: activityIndicatorView.rx.isAnimating)
    .disposed(by: disposeBag)

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