GestureRecognizer not responding to tap

Didia picture Didia · Sep 25, 2014 · Viewed 64.9k times · Source

After initialisation of by subclass of UIImageView I have the following line of code:

self.userInteractionEnabled = true
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "handleTap:"))

I created the necessary associated function :

func handleTap(gestureRecognizer: UITapGestureRecognizer) {
    print("In handler")
}

On tapping on the view in question, "In handler was never printed to the console". I then removed the handler function to see if the compiler would complain about the missing function. It didn't.

I'm positively stumped. I'd truly appreciate any light people can shed on this.

Update: My class is actually a UIImageView as opposed to UIView

Answer

Scooter picture Scooter · Nov 28, 2015

I was using UITapGestureRecognizer that I placed on a UILabel using Storyboard.

To get this to work I also had to place a checkmark in the block labeled: "User Interaction Enabled" in the UILabel Attributes Inspector in the Storyboard.

enter image description here