Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues using UITapGestureRecognizers in Interface Builder

I'm attempting to use the UITapGestureRecognizer object that can be found in Interface Builder. I've dragged a single "UITapGestureRecognizer" from the object library to a single view xib. I then create an IBAction method from this tap gesture, for a simple test, I'm just printing an "NSLog" message to the console once there is a tap on the view. I've run this, and the tap method isn't being called. I right click the view in IB and I noticed that there is a warning "!" on the view's "Outlet Collections" I see:

Outlet Collections
gestureRecognizers - Tap Gesture Recognizer (!)

The warning states: UIView does not have an outlet collection named gestureRecognizers.

What do I need to do to remedy this?

like image 305
5StringRyan Avatar asked Dec 12 '11 22:12

5StringRyan


2 Answers

Mr.Anonymous solution is correct. No need to implement the delegate in the view controller or set it. However, you should check that User interaction enabled is checked (in the properties window on the right), especially if you are attaching the recognizer to a label.

like image 83
hammady Avatar answered Oct 13 '22 13:10

hammady


I think you have not wired the UITapGestureRecognizer properly to your code.

When you drop a UITapGestureRecognizer on your xib Xcode automatically makes the necessary referencing outlet connections.

You only need to create an IBAction method in your code and then wire it to the selector of the UITapGestureRecognizer placed in xib.

I have attached screenshots for ur reference.

enter image description here

enter image description here

Hope this helps!!

like image 25
Mr.Anonymous Avatar answered Oct 13 '22 15:10

Mr.Anonymous