【发布时间】:2018-07-19 12:08:04
【问题描述】:
我在静态 tableviewcontroller 中有几个 UITextField。我为每个文本字段指定了一个标签值,这样当用户在键盘上单击下一步时,我可以获得带有下一个标签的文本字段并调用 becomeFirstResponder 以便用户在文本字段之间导航。
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
let tag = textField.tag
if let tf = self.view.viewWithTag(tag + 1) as? UITextField {
tf.becomeFirstResponder()
}
}
这基本上可以工作。但是,当我使用 ReactiveKit/Bond 时,特别是当我在 viewdidload 中调用以下行(假设 lastName 是下一个文本字段)以将 UI 与模型绑定时:
profile.lastName.bidirectionalBind(to: lastName.reactive.text)
下一个文本字段 (lastName) 将进入编辑模式几毫秒,然后键盘被关闭,文本字段不再处于编辑模式。
当我注释掉粘合线时,逻辑就会成功。我试过用单向键替换双向键或调用 obserNext 但这也会导致同样的问题。
【问题讨论】:
标签: ios swift uitextfield uitextfielddelegate reactivekit