Search code examples
objective-ciosuitableviewuikituitapgesturerecognizer

shouldReceiveTouch on UITableViewCellContentView


I'm trying to ignore UITapGestureRecognizer taps on a UITableView with the following:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
      if ([touch.view isKindOfClass:[UITableViewCellContentView class]]) {
          return NO; // ignore the touch
      }
      return YES; // handle the touch
}

It won't compile: "Use of undeclared identifier 'UITableViewCellContentView'

Undocumented class? Need to subclass? Better way to accomplish this?

Thanks for any help.


Solution

  • This seems to do it:

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        if([touch.view isKindOfClass:[UITableViewCell class]]) {
             return NO;
        }
        // UITableViewCellContentView => UITableViewCell
        if([touch.view.superview isKindOfClass:[UITableViewCell class]]) {
             return NO;
        }
        // UITableViewCellContentView => UITableViewCellScrollView => UITableViewCell
        if([touch.view.superview.superview isKindOfClass:[UITableViewCell class]]) {
             return NO;
        }
        return YES; // handle the touch
    }