In my app for a specific reason i want a UIImageView touchable so that when user taps it pushes to a new view controller. I know to do the same with UIButton. But i want a UIImageView to do this now. How will i do it? Here's my code for UIImageView
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 100, 50, 50)];
[imageView setImage:[UIImage imageNamed:@"myImage.png"]];
imageView.userInteractionEnabled = YES;
[self.view addSubview:imageView];
[imageView release];
Here is the complete code as Mat discussed about:
As @Kory Sharp said you can use the UITapGestureRecognizer
Handle the method
I am using a single tap gesture recognizer here
While it would be easier to make this a UIbutton (as you me mentioned), you can implement a UITapGestureRecognizer for the UIImageView. You'll also need to enable user interaction on the view with the userInteractionEnabled property.