使用RxSwift观察UITextField.editing [英] Observing UITextField.editing with RxSwift

查看:772
本文介绍了使用RxSwift观察UITextField.editing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to observe the property UITextfield.editing. I'm using this code:

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

但在运行过程中,它只执行一次。我如何解决这个问题,请

But in the process of running, it's only performed once. How do I solve this,please

推荐答案

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

Don't observe the editing property, because it's not just a stored property. It's defined as:

public var editing: Bool { get }

所以你不知道UIKit实际上是如何获得这个价值的。

So you don't know how UIKit is actually getting that value.

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

Instead, use rx.controlEvent and specify the control events you're interested in, like so:

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

这篇关于使用RxSwift观察UITextField.editing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆