Skip to content

Instantly share code, notes, and snippets.

@hoandang
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoandang/739be2045351c4719804 to your computer and use it in GitHub Desktop.
Save hoandang/739be2045351c4719804 to your computer and use it in GitHub Desktop.

Add UITextFieldDelegate then assign delegate for every uitextfield in the view

// Detect user touches outside keyboard and dismiss the keyboard
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

[texfield addTarget:self action:@selector(dismissKeyboard:) forControlEvents:UIControlEventEditingDidEndOnExit];


// Dismiss keyboard when return key is pressed
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment