ios - 使用 RxSwift 观察 UITextField.editing

标签 ios swift rx-swift reactivex rx-cocoa

我想观察属性 UITextfield.editing。我正在使用这段代码:

self.money.rx_observe(Bool.self, "editing").subscribeNext { (value) in
    print("")
}.addDisposableTo(disposeBag)

但是在运行的过程中,只执行了一次。请问这个怎么解决

最佳答案

不要观察 editing 属性,因为它不仅仅是一个存储属性。它被定义为:

public var editing: Bool { get }

所以您不知道 UIKit 实际上是如何获取该值的。

相反,使用 rx.controlEvent 并指定您感兴趣的控制事件,如下所示:

textField.rx.controlEvent([.editingDidBegin, .editingDidEnd])
    .asObservable()
    .subscribe(onNext: { _ in
        print("editing state changed")
    })
    .disposed(by: disposeBag)

关于ios - 使用 RxSwift 观察 UITextField.editing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39627440/

相关文章:

ios - 如何将 rx_tap (UIButton) 绑定(bind)到 ViewModel?

iphone - 如何将字符串数组发送到 UIActionSheet varargs init 方法中?

ios - UIButton 不显示我的数组的 UIbuttons 背景图像

Cocoa NSTextField 更改占位符颜色

ios - CGContextSaveGState : invalid context 0x0 at App Launch

python - 苹果对将 ios 应用程序连接到 python 代码的偏好是什么?

swift - 使用 RxSwift 和 MVVM 处理错误

memory - 在 RxSwift 闭包上使用 'self' ...实例方法作为参数怎么样?

ios - 如何从 CocoaPods 迁移到 Carthage?

ios - NSFont 和 UIFont 有什么区别