如何从用户启动的和以编程方式对UITextField文本属性进行更改的信号?通过使用continuousTextValues,仅在用户启动更改时报告信号.如果以编程方式设置textField.text,则不会触发信号.
这就是我使用continuousTextValues的方式:
textField.reactive.continuousTextValues.observeValues { value in print("Value: \(value)") }
如果我手动设置文本,它不会被触发:
textField.text = "Test"
信号continuousTextValues将仅在用户使用键盘输入时触发.您可以尝试:
var characters = MutableProperty("") tf.reactive.text <~ characters tf.reactive.continuousTextValues.observeValues { [weak characters = characters] (text) in characters?.value = text! } tf.reactive.textValues.observeValues { [weak characters = characters] (text) in characters?.value = text! } characters.producer.skip(while: { $0.isEmpty }).startWithValues { (text) in log.debug("text = \(text)") } characters.value = "shaw"