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
Swift 5
You can easily switch to another TextField when clicking return key in keyboard.
UITextFieldDelegate and add the textFieldShouldReturn(_:) delegate method in ViewController delegate option. Note : Do this for all TextFieldCreate an IBOutlet for all TextFields
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var txtFieldName: UITextField!
@IBOutlet weak var txtFieldEmail: UITextField!
@IBOutlet weak var txtFieldPassword: UITextField!
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField == txtFieldName {
textField.resignFirstResponder()
txtFieldEmail.becomeFirstResponder()
} else if textField == txtFieldEmail {
textField.resignFirstResponder()
txtFieldPassword.becomeFirstResponder()
} else if textField == txtFieldPassword {
textField.resignFirstResponder()
}
return true
}
}