How to call didSelectRowAtIndexPath method using UITapGestureRecognizer?

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; } 
+6
source share
1 answer

Setting the gesture recognizer cancels the touchesInView property to NO, it is YES by default, it does not allow touches to reach basic representations if GR recognizes its gesture.

+14
source

Source: https://habr.com/ru/post/921635/


All Articles