1

I am using :

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                               initWithTarget:self
                               action:@selector(dismissKeyboard:)];
[self.view addGestureRecognizer:tap];

in order to close keyboard when clicked anywhere else from UITextField.

However in my view, I have UITableView , and I have to detect when click on the rows of UITableView. Because of UITapGestureRecognizer my didSelectRowAtIndexPath function is not called. Is there any way to detect whether the clicked object is UITableViewCell?

Jeyhun Karimov
  • 1,295
  • 19
  • 27

2 Answers2

5

You can get thouch event of Gesture from

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 

you detect touch of gesture so do logically like bellow:

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isKindOfClass:[UITextFiled class]])
    {
        return FALSE;
    }
    else
    {

     // here is remove keyBoard code
        return TRUE;
    }
}
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
0

Implement this delegate method gestureRecognizerShouldBegin:, check and cancel your gesture callback which happen on tableview cell(row) and trigger tableview's delegate method.

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    if ([gestureRecognizer.view isKindOfClass:[UITableViewCell class]])
    {
        return NO;
    }
    return YES

}
Mani
  • 17,549
  • 13
  • 79
  • 100