I’m attempting to implement a tap-gesture recognizer on a UIImageView. However I can’t get the method that handles the tap event to fire. I’ve compared my code against the answers to many similar questions on stackoverflow but still the problem persists. Below is the relevant code from my application. Can someone show me what I’ve done wrong?
ViewController.h
IBOutlet UIImageView *topLeftImage;
-(IBAction)handleSingleTap:(UITapGestureRecognizer*)gestureView;
ViewController.m
- (void)viewDidUnload
{
[super viewDidUnload];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
topLeftImage.userInteractionEnabled = YES;
[topLeftImage addGestureRecognizer:singleTap];
}
- (void)handleSingleTap:(UITapGestureRecognizer *)gestureRecognizer {
NSLog(@"Tap detected. Booyah!");
}
Try this instead. You put your code in viewDidUnload, completely the wrong place. You want viewDidLoad.