The crash is probably happening in the gestureRecognizerShouldBegin:
delegate method which gets called for any gesture recognizer for which this class instance is a delegate.
This includes gesture recognizers that iOS might be creating and assigning itself to the underlying standard UITableViewCell
.
iOS must be adding a UILongPressGestureRecognizer
to the cell (for its own use) and that delegate method gets called for it as well as your UIPanGestureRecognizer
.
Since a UILongPressGestureRecognizer
does not have a translationInView:
method, this results in the "unrecognized selector" crash.
At a minimum, you can check whether the gestureRecognizer
parameter is actually a UIPanGestureRecognizer
and, if not, do nothing and just return YES
.
Also note that even though you've declared the type of the parameter to the gestureRecognizerShouldBegin:
method as a UIPanGestureRecognizer *
, this does not actually prevent any UIGestureRecognizer *
from calling it (ie. leave the parameter type as the generic UIGestureRecognizer *
so the meaning and implications are clear).
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
//if gestureRecognizer is not a UIPanGestureRecognizer, let it go...
if (! [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])
{
return YES;
}
//Cast the gestureRecognizer as a UIPanGestureRecognizer so
//compiler knows and checks what we're doing...
UIPanGestureRecognizer *pgr = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint translation = [pgr translationInView:[self superview]];
// Check for horizontal gesture
if (fabsf(translation.x) > fabsf(translation.y)) {
return YES;
}
return NO;
}