I have an image displayed in on my app that I'm creating in Swift using Xcode and I want to for example print "Image Clicked" whenever the image is tapped. Here's what I got:
This is a function that is supposed to get called whenever users tap the image:
func imageViewTapped(imageView: UIImageView) {
print("Image Clicked")
}
I have this function that adds the user interaction with the image:
func tapRecognition(image: UIImageView) {
image.isUserInteractionEnabled = true
let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector(("imageViewTapped:")))
image.addGestureRecognizer(tapRecognizer)
}
And last but not least I created an image of type UIImageView in my viewDidLoad() function and I called:
tapRecognition(image: imageView)
When I run this and click on the image, I get an error that states:
terminating with uncaught exception of type NSException.