I’m working on an app in which I want the user to be able to tap an image and trigger another method (already written and tested; it works), but I’ve gotten very confused about what I need to do to make this work. I’ve used the XIB to set up the UIImageView (and I know I need to drag a UITapGestureRecognizer onto the UIImageView, and I know I need to allocate and initiate it with target and action in viewDidLoad), but I don’t know what to connect to what in the XIB after that, or what properties/methods to write. (The state of the UITapGesture recognizer is irrelevant–it should do the same thing whether it’s UIGestureRecognizerStateBegan or UIGestureRecognizerStateEnded.)
What are my next steps?
As usual, thanks very much ahead of time.
I’m personally a fan of setting these up with code, so here’s an example of that. First of all in your header file you will want to create an
IBOutletfor theUIImageViewand then link the outlet to your image view in interface builder.Then in
viewDidLoad(or where ever you want really) you can set up the recognizer and add it to the image view.IMPORTANT: Make sure you enable user interaction on the image view or this won’t work!
Hope this helps!