【问题标题】:Change focus on textfield after typing in SwiftUI输入 SwiftUI 后更改文本字段的焦点
【发布时间】:2020-03-11 13:37:36
【问题描述】:

我想在我的 SwiftUI 应用程序中创建一个代码验证文本字段,我已经在 UIKit 中这样做了。

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    if !(string.isEmpty) {
        textField.text = string
        if textField == textField1 { textField2.becomeFirstResponder() }
        else if textField == textField2 { textField3.becomeFirstResponder() }
        else if textField == textField3 { textField4.becomeFirstResponder() }
        else if textField == textField4 { textfield5.becomeFirstResponder() }
        else { textField.resignFirstResponder() }
        return false
    } else {
        textField.text = string
        if textField == textfield5 { textField4.becomeFirstResponder() }
        else if textField == textField4 { textField3.becomeFirstResponder() }
        else if textField == textField3 { textField2.becomeFirstResponder() }
        else if textField == textField2 { textField1.becomeFirstResponder() }
        else { textField.resignFirstResponder() }
        return false
    }
}

现在我看到了一些关于这个问题的答案,例如:

Focus on the next TextField/SecureField in Swiftui

但它没有帮助。

【问题讨论】:

    标签: ios swift swiftui textfield


    【解决方案1】:

    在 SwiftUI 中似乎没有这个委托

    【讨论】:

      猜你喜欢
      • 2015-09-21
      • 2020-11-14
      • 2021-03-31
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      • 2020-06-28
      • 2020-05-26
      • 1970-01-01
      相关资源
      最近更新 更多