How to dismiss keyboard iOS programmatically when pressing return

The simple way is to connect the delegate of UITextField to self (self.mytestField.delegate = self) and dismiss the keyboard in the method textFieldShouldReturn using [textField resignFirstResponder];

Another way to dismiss the keyboard is the following:


[self.view endEditing:YES];



Put [self.view endEditing:YES]; where you would like to dismiss the keyboard (Button event, Touch event, etc.).

Leave a Comment