I am developing an iPad app that has a large number of UIViewControllers
, UITableViews
(with cells with accessoryViews
of UIText
Here is a much easier and efficient way of dealing with that. This is gonna work for any UITextField in your view controller. You can even add it to your base view controller (if you have got one) and it will work like a charm.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if (![[touch view] isKindOfClass:[UITextField class]]) {
[self.view endEditing:YES];
}
[super touchesBegan:touches withEvent:event];
}