12
votes

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?

7
I went thru the same exercise and it works for me. I am using xCode 4.2 with iOS SDK5. The warning message is there but it still print the NSLog message.Ken W
Have any idea what the warning is for or how it can be remedied?5StringRyan
I suspect the gestureRecognizers is not define as IBOutlet but some how when we drop the gestureRecognizer control in the IB and it knows how to wire it up for us.Ken W
I get the same problem and although it seems to do something when I double tap my view ... it crashes.Lee Probert
They're "Outlet Collections", not "Outlook Collections" ;)Jacob Relkin

7 Answers

4
votes

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.

4
votes

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!!

2
votes

I had forgotten to check that User Interaction Enabled has to be checked for the views the gesture recognizer is added.

1
votes

Two things to check: Does your view controller (the one that contains the UIView) implement the UIGestureRecognizerDelegate protocol?

Once it implements UIGestureRecognizerDelegate, make sure you've set the gesture recogniser's delegate property to the view controller. I used a storyboard to make the connection.

I do this and I don't get any errors (IOS 5.1, xCode 4.3).

1
votes

I did this to add a Double Tap Gesture to my Navigation bar, completely in code and found it very easy to use ....

In view did load ...

//Add double tap gesture to Navbar
UITapGestureRecognizer* tapRecon = [[UITapGestureRecognizer alloc]
                                    initWithTarget:self action:@selector(navigationBarDoubleTap:)];
tapRecon.numberOfTapsRequired = 2;
[self.navigationController.navigationBar addGestureRecognizer:tapRecon];

I then have a method ...

#pragma mark - Auto Refresh Method
- (void)navigationBarDoubleTap:(UIGestureRecognizer*)recognizer {
      //Do Stuff Here
}

Maybe you could adapt this.

Plasma

0
votes

Take a look at this.

Specifically the screen shot of the outlet setup. Hopefully that will help.

0
votes

The warning shouldn't be an issue. It is only there because you can add multiple gesture recognizers as an IBOutlet Collection but this isn't required.

Turn on zombies in your scheme to get better error messages whilst debugging. In my case the View controller I was trying to message with my gesture handler wasn't being instantiated in Interface Builder.

Also, it's not necessary to implement the delegate protocol and it will work on any UIView.