输入 SwiftUI 后更改文本字段的焦点

Posted

技术标签:

【中文标题】输入 SwiftUI 后更改文本字段的焦点【英文标题】:Change focus on textfield after typing in 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

但它没有帮助。

【问题讨论】:

【参考方案1】:

在 SwiftUI 中似乎没有这个委托

【讨论】:

以上是关于输入 SwiftUI 后更改文本字段的焦点的主要内容,如果未能解决你的问题,请参考以下文章