Switching between Text fields on pressing return key in Swift

前端 未结 15 1438
名媛妹妹
名媛妹妹 2020-12-04 09:25

I\'m designing an iOS app and I want that when the return key is pressed in my iPhone it directs me to the next following text field.

I have found a couple of similar

15条回答
  •  抹茶落季
    2020-12-04 09:35

    the easiest way to change to next text Field is this no need for long code

    override func viewDidLoad() {
            super.viewDidLoad()
    
            emailTextField.delegate = self
            passwordTextField.delegate = self
        }
    
    
        func textFieldShouldReturn(_ textField: UITextField) -> Bool {
            if textField == emailTextField {
                passwordTextField.becomeFirstResponder()
            }else {
                passwordTextField.resignFirstResponder()
            }
                return true
        }
    

提交回复
热议问题