UITapGestureRecognizer not working in UIImageView

xonegirlz picture xonegirlz · Jul 19, 2012 · Viewed 26.7k times · Source

I had the following code:

UITapGestureRecognizer *showStoryTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showNewsStory:)];
[showStoryTapRecognizer setDelegate:self];
[self.storyImageView_ addGestureRecognizer:showStoryTapRecognizer];
[showStoryTapRecognizer release];

This however doesn't trigger the showNewsStory, why is this? I have enabled userInteraction in the image view.

Answer

Kjuly picture Kjuly · Jul 19, 2012

You should enable user interaction for UIImageView object:

[self.storyImageView_ setUserInteractionEnabled:YES];

EDIT:

Try to remove the

[showStoryTapRecognizer setDelegate:self];

I don't think UITapGestureRecognizer has its delegate methods as far as I know.