Skip to content

Instantly share code, notes, and snippets.

@sam33r
Created April 15, 2014 21:23
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 sam33r/10776947 to your computer and use it in GitHub Desktop.
Save sam33r/10776947 to your computer and use it in GitHub Desktop.
iOS wiring to end editing when the user touches anywhere other than the keypad
// Useful for when the keypad is open.
// In the view controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Listen for taps to end editing
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[self.view addGestureRecognizer:gestureRecognizer];
}
- (void)tap:(UIGestureRecognizer *)ui
{
[self.view endEditing:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment