I have a custom tableviewCell with an UIImageView
imgView inside. I added UITapGestureRecognizer
to imgView, so that I can change image of imgView whenever I tap to it. However, when I tap to imgView, didSelectRowAtIndexPath
is also triggered. What I want is:
- When tapping outside imgView: Trigger
didSelectRowAtIndexPath
- When tapping inside imgView: Block
didSelectRowAtIndexPath
, just call gesture callback to change image of imgView.
Callback function is already called when I tap inside imgView but I can not block didSelectRowAtIndexPath in that case. I've been searching around for hours but have not found the solution yet. I'm using objective-c. Anyone have any idea for my problem? Thank all!
Update
Finally I found out what my mistake is.
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onFavouriteIconTapped:)];
tapGesture.cancelsTouchesInView = NO; // this should be YES by default
[_ivImageView addGestureRecognizer:tapGesture];
Just set cancelsTouchInView = YES
fix my problem. If the value is YES, touch event will be consumed by ivImageView and cell wont be selected. Hope this will help someone who has the same problem.