Last active
April 18, 2020 10:53
-
-
Save nurtugan/1ff0ebf6fa1a8a16e75dd270736d36c7 to your computer and use it in GitHub Desktop.
Switching between Text Fields on pressing return key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension MyViewController: UITextFieldDelegate { | |
func textFieldShouldReturn(_ textField: UITextField) -> Bool { | |
// Try to find next responder | |
if let nextTextField = textField.superview?.viewWithTag(textField.tag + 1) as? UITextField { | |
nextTextField.becomeFirstResponder() | |
} else { | |
// Not found, so remove keyboard | |
textField.resignFirstResponder() | |
} | |
// Do not add a line break | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment