我正在尝试将NVActivityIndicatorView
和RxSwift
一起使用。
我正在像下面那样扩展MVVM
:
NVActivityIndicatorView
并绑定这样的数据:
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()
}
}
}}
但是我得到了这个错误:
splashVM.loading.bind(to: NVActivityIndicatorView.rx.isAnimating).disposed(by: disposeBag)
如果我将Instance member 'isAnimating' cannot be used on type 'Reactive<NVActivityIndicatorView>'
设置为static,则该错误消失了,但又弹出了另一个错误:
isAnimation
到底是什么问题?我应该改变什么?
答案 0 :(得分:1)
您将其绑定错误。您需要绑定到特定的活动指示器视图而不是类:
let activityIndicatorView: NVActivityIndicatorView
splashVM.loading
.bind(to: activityIndicatorView.rx.isAnimating)
.disposed(by: disposeBag)