UITapGestureRecognizer on UIImageView within UITablevlewCell not getting called

Herman picture Herman · Oct 12, 2011 · Viewed 17.3k times · Source

I currently have a custom UITableViewCell which contains a UIImageView and trying to add a UITapGestureRecognizer on the UIImageView with no luck. here is snippet of the code.

//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;
tap.delegate = self;
[imageView addGestureRecognizer:tap];
[tap release];

// handle method
- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer {
    RKLogDebug(@"imaged tab");
}

I've also set userInteractionEnabled on the cell and the superview of the UIImageView but still no luck, any hints?

EDIT:

I've also remove cell's selection by cell.selectionStyle = UITableViewCellSelectionStyleNone; Could this be a problem

Answer

EmptyStack picture EmptyStack · Oct 12, 2011

UIImageView's user interaction is disabled by default. You have to enable it explicitly to make it respond to touches.

imageView.userInteractionEnabled = YES;