I searched for watches on Google and Stackoverflow, tried them, but no luck.
I have a UITableView tblDepartment and a UISearchBar studentSearch above it.
I add a UITapGestureRecognizer to cancel the keyboard from the studentSearch text field when users go beyond the search field:
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)]; [self.tblDepartment addGestureRecognizer:gestureRecognizer]; - (void)hideKeyboard { [studentSearch resignFirstResponder]; }
After that, the didSelectRowAtIndexPath:(NSIndexPath *)indexPath no longer called when I select a row in tblDepartment . I know the reason for gestureRecognizer .
So how can I hide the keyboard and allow the user to select a row?
I tried this code but it did not work:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ([touch.view isDescendantOfView:tblDepartment]) { return NO; } return YES; }
source share