For some reason, my UITapGestureRecognizer
is not calling it's method when I tap a UIButton. What's really weird is that I used breakpoints in Xcode to make sure that the gestureRecognizer:shouldReceiveTouch:
method is returning YES. The gesture should be calling it's method, but it isn't. I have cancelsTouchesInView
set to YES, but it doesn't seem to do anything.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass: [UIButton class]] && !editingTaskName)
return NO;
else if ([touch.view isKindOfClass: [UITextField class]])
return NO;
return YES; // handle the touch
}
Here's the code where I set up all my gesture recognizers. Maybe the others are interfering with my tap gesture.
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @selector(longPress:)];
[longPress setMinimumPressDuration: 0.3];
[longPress setDelaysTouchesBegan: YES];
[self setLongPressGesture: longPress];
[[self tableView] addGestureRecognizer: longPress];
UITapGestureRecognizer *backToTableView = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(backTapRecognized:)];
[backToTableView setCancelsTouchesInView: YES];
[backToTableView setDelegate: self];
[backToTableView setEnabled: NO];
[self setBackTapGesture: backToTableView];
[[self tableView] addGestureRecognizer: backToTableView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(hideShowEditing:)];
[tap setCancelsTouchesInView: YES];
[tap setDelegate: self];
[self setEditTap: tap];
[[self tableView] addGestureRecognizer: tap];