StuartM
StuartM

Reputation: 6813

Detecting touch on UIImageView from within custom Cell

I have a custom cell layout with some UILabels and UIImageViews within the UITableViewCell.

I have already setup the cells in Storyboard and linked up the relevant outlets. I have also already handled the cell being selected with -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath.

What I am trying to do now is link a specific image view from within the cell to load a different View Controller. I have the segue already setup in the storyboard.

How do I setup a gesture recogniser just from this UIImageView to the segue?

So I am looking for the following:
If you tap the cell the didSelectRowAtIndex* is run as expected.
But if you tap the UIImageView from within the cell then the didSelectRow* is not run and another method (with the segue in) is run instead.

Upvotes: 0

Views: 356

Answers (1)

StuartM
StuartM

Reputation: 6813

I created a Gesture Recognizer in the cell creation method: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)];
    imageTap.cancelsTouchesInView = YES;
    imageTap.numberOfTapsRequired = 1;
    [cell.turnThumbnailImage addGestureRecognizer:imageTap];

Upvotes: 1

Related Questions