For iOS and Xcode, can we create an Action for a UIImageView object?

interface-builder, ios, xcode

Solution

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] 
                                     initWithTarget:self 
                                     action:@selector(actionHandleTapOnImageView)];
[singleTap setNumberOfTapsRequired:1];
originalImageView.userInteractionEnabled = YES;
[originalImageView addGestureRecognizer:singleTap];
[singleTap release];




-(void)actionHandleTapOnImageView
{
NSLog(@"actionHandleTapOnImageView");
}

Problem

It is easy that we create an Action for a `UIButton`, we just Ctrl drag the button on the canvas in Interface Builder to the `@implementation` part of our code (in the Assistant Editor). But what about a `UIImageView`? I want to say, if the user taps on this image (which is actually a good looking icon), then do something, but how can the Action be added because Ctrl drag doesn't do anything?

Original source