Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 446
Jimmy_m Avatar asked Nov 07 '12 17:11

Jimmy_m


1 Answers

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
}
like image 102
Jimmy_m Avatar answered Sep 23 '22 02:09

Jimmy_m