So I have this UITableView
that contains few rows, when clicked on a row, another UIViewController
is pushed with the specific row details. My problem is that I want to dismiss keyboard with any touch on the screen (also on the UITableView
), but when I do it, and click on the UITableView
row, the keyboard dismisses, but the didSelectRow
method is not working. It wont push the new ViewController
once clicked on the cell.
Also the other way around, once I change it, you can click on the TableView cell, the keyboard dismiss and the other ViewController is pushed, but the touch on any other place is not dismissing the keyboard.
What should I do?
- (IBAction)hideKeyboard:(id)sender
{
[tfFoodsSearchQuery resignFirstResponder];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UITableView class]])
{
// we touched a button, slider, or other UIControl
return YES; // handle the touch
}
NSLog(@"Touch");
return NO; // ignore the touch
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(hideKeyboard:)];
[self.view addGestureRecognizer:tap];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
gestureRecognizer.delegate = self;
[self.tvFoods addGestureRecognizer:gestureRecognizer];
}
Thanks!