textfieldshouldreturn not not切换文本字段

时间:2017-06-02 23:48:23

标签: swift uitextfield first-responder

在查看上一个问题提供的示例之后&回答...... Switching between Text fields on pressing return key in Swift,我认为应用函数会相对无缝。但是,在应用下面的代码后,切换到新的第一响应者不起作用。我有代理设置,标签设置,功能设置,仍然没有进展。我在这个逻辑中明显遗漏了一些东西,但似乎无法意识到它是什么。

    override func viewDidLoad() {
    super.viewDidLoad()

    self.Class1TF.delegate = self as? UITextFieldDelegate
    self.Credits1TF.delegate = self as? UITextFieldDelegate
    self.Grade1TF.delegate = self as? UITextFieldDelegate
    self.CumCredits.delegate = self as? UITextFieldDelegate
    self.CumGPA.delegate = self as? UITextFieldDelegate

    Class1TF.tag = 0
    Credits1TF.tag = 1
    Grade1TF.tag = 2
    CumCredits.tag = 3
    CumGPA.tag = 4

    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(Classes2Controller.dismissKeyboard))
    view.addGestureRecognizer(tap)

    func textFieldShouldReturn(_ textField: UITextField) -> Bool
    {
        // Try to find next responder
        if let nextField = textField.superview?.viewWithTag(textField.tag + 1) as? UITextField {
            nextField.becomeFirstResponder()
        } else {
            // Not found, so remove keyboard.
            Class1TF.resignFirstResponder()
            return true
        }
        // Do not add a line break
        return false
    }

0 个答案:

没有答案