I\'d like to know the simplest code to dismiss the number pad keyboard when tapping anywhere outside the number pad. It\'s a simple application to input a number inside a te
If you've made a custom number pad or other popover, another solution would be to use a gesture recognizer in the init of your UIView like this:
tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
tapper.cancelsTouchesInView = NO;
[self addGestureRecognizer:tapper];
_yourViewController = [[CustomViewController alloc] init];
_yourPopoverController = [[UIPopoverController alloc] initWithContentViewController:_yourViewController];
_yourPopoverController.popoverContentSize = CGSizeMake(550, 300);
_yourViewController.delegate = self;
And have the handleSingleTap dismiss the popover if visible and dismiss editing:
- (void)handleSingleTap:(UITapGestureRecognizer *) sender
{
if ([_yourPopoverController isPopoverVisible]) {
[_yourPopoverController dismissPopoverAnimated:YES];
}
[self endEditing:YES];
}