Dismiss Keyboard on enter

It’s a common thing in iOS to hide the keyboard on a enter press when filling in some text fields. This is easily accomplished by adding the following code snippet to you’re project.


First add the UITextFieldDelegate to your controller view.

@interface myViewController : UIViewController  <UITextFieldDelegate>


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if([string isEqualToString: @"\n"]){
        [textField resignFirstResponder];
    return YES;

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>