UITapGestureRecognizer on UIImageView within UITablevlewCell not getting called UITapGestureRecognizer on UIImageView within UITablevlewCell not getting called ios ios

UITapGestureRecognizer on UIImageView within UITablevlewCell not getting called


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

imageView.userInteractionEnabled = YES;


Swift 3

This worked for me:

self.isUserInteractionEnabled = true


In my case it looks like :

- (UITableViewCell *)tableView:(UITableView *)tableView         cellForRowAtIndexPath:(NSIndexPath *)indexPath {    NSString *cellIdentifier = CELL_ROUTE_IDENTIFIER;    RouteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];    if (cell == nil) {        cell = [[RouteTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault                                         reuseIdentifier:cellIdentifier];    }    if ([self.routes count] > 0) {        Route *route = [self.routes objectAtIndex:indexPath.row];        UITapGestureRecognizer *singleTapOwner = [[UITapGestureRecognizer alloc] initWithTarget:self                                                                                    action:@selector(imageOwnerTapped:)];        singleTapOwner.numberOfTapsRequired = 1;        singleTapOwner.cancelsTouchesInView = YES;        [cell.ownerImageView setUserInteractionEnabled:YES];        [cell.ownerImageView addGestureRecognizer:singleTapOwner];    } else {        cell.selectionStyle = UITableViewCellSelectionStyleNone;    }    return cell;}

And selector :

- (void)imageOwnerTapped:(UISwipeGestureRecognizer *)gesture {    CGPoint location = [gesture locationInView:self.tableView];    NSIndexPath *tapedIndexPath = [self.tableView indexPathForRowAtPoint:location];    UITableViewCell *tapedCell  = [self.tableView cellForRowAtIndexPath:tapedIndexPath];    NSIndexPath *indexPath = [self.tableView indexPathForCell:tapedCell];    NSUInteger index = [indexPath row];    Route *route = [self.routes objectAtIndex:index];}