3 quick and easy steps
Add a UITextFieldDelegate to your class, like a UITextFieldDelegate below:
class RegisterVC: UIViewController, UITextFieldDelegate {
in the class implementation add the delegate function textFieldShouldEndEditing: ::
internal func textFieldShouldReturn(_ textField: UITextField) -> Bool { self.view.endEditing(true) return true }
and as a last step, set your UITextField UITextField to yourself, somewhere suitable. For example, inside the viewDidLoad function:
override func viewDidLoad(){ super.viewDidLoad() myTextField1.delegate = self myTextField2.delegate = self .. .. }
Now, when the user presses the return key, the keyboard will be rejected.
I also prepared a code snippet, you can check it here .
Mert Celik Apr 20 '18 at 18:24 2018-04-20 18:24
source share