加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 每次在ReactiveCocoa 5中UITextField文本属性发生更改

发布时间:2020-12-14 05:24:06 所属栏目:百科 来源:网络整理
导读:如何从用户启动的和以编程方式对UITextField文本属性进行更改的信号?通过使用continuousTextValues,仅在用户启动更改时报告信号.如果以编程方式设置textField.text,则不会触发信号. 这就是我使用continuousTextValues的方式: textField.reactive.continuou
如何从用户启动的和以编程方式对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"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读