Tap Recognition for UIImageView in the UITableViewCell Tap Recognition for UIImageView in the UITableViewCell ios ios

Tap Recognition for UIImageView in the UITableViewCell


This is actually easier than you would think. You just need to make sure that you enable user interaction on the imageView, and you can add a tap gesture to it. This should be done when the cell is instantiated to avoid having multiple tap gestures added to the same image view. For example:

- (instancetype)initWithCoder:(NSCoder *)aDecoder{    if (self = [super initWithCoder:aDecoder]) {        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myTapMethod:)];        [self.imageView addGestureRecognizer:tap];        [self.imageView setUserInteractionEnabled:YES];    }    return self;}- (void)myTapMethod:(UITapGestureRecognizer *)tapGesture{    UIImageView *imageView = (UIImageView *)tapGesture.view;    NSLog(@"%@", imageView);}


Try this

//within cellForRowAtIndexPath (where customer table cell with imageview is created and reused)UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];tap.cancelsTouchesInView = YES;tap.numberOfTapsRequired = 1;[imageView addGestureRecognizer:tap];// handle method- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer {    RKLogDebug(@"imaged tab");}

make sure u have....

imageView.userInteractionEnabled = YES;