How do you get a signal every time a UITextField text property changes in RxSwift

前端 未结 4 1862
挽巷
挽巷 2021-02-18 23:36

How do you get a signal from programmatically made changes to UITextField text property? By using rx.text only reports a signal when the user input the text by keyboard. If you

4条回答
  •  佛祖请我去吃肉
    2021-02-18 23:50

    If u are setting textfield.text programmatically then you can perform any actions over there. You don't need the subscription block.

    As textfield is in inactive state your textfield.text subscription won't get called, rather u have to observe the textfield text.

    Use bindings for text changes will solve your problem.

    let textChange = Variable(true)
    _ = textChange.asObservable().bindTo(textfield.rx.text)
    

提交回复
热议问题