Swift UITextFieldShouldReturn Return Key Tap

后端 未结 4 1903
旧时难觅i
旧时难觅i 2021-02-01 01:26

(iOS8, Xcode6, Swift) Using Swift, how do I capture a tap on the \"Return\" button?

The doc at the following link specifies using the textFieldShouldReturn

4条回答
  •  遇见更好的自我
    2021-02-01 02:06

    In Swift 4.2 and Xcode 10.1

    //UITextField delegate method
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    
        if textField == TF1 {
            textField.resignFirstResponder()//
            TF2.becomeFirstResponder()//TF2 will respond immediately after TF1 resign.
        } else if textField == TF2  {
            textField.resignFirstResponder()
            TF3.becomeFirstResponder()//TF3 will respond first
        } else if textField == TF3 {
            textField.resignFirstResponder()
        }
        return true
    }
    

提交回复
热议问题