12

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?

Marcy
  • 4,611
  • 2
  • 34
  • 52
5StringRyan
  • 3,604
  • 5
  • 46
  • 69
  • 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 Dec 18 '11 at 04:08
  • Have any idea what the warning is for or how it can be remedied? – 5StringRyan Dec 18 '11 at 23:23
  • 1
    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 Dec 20 '11 at 17:51
  • I get the same problem and although it seems to do something when I double tap my view ... it crashes. – Lee Probert Jun 18 '12 at 16:05
  • They're "Outlet Collections", not "Outlook Collections" ;) – Jacob Relkin Nov 17 '12 at 08:30

7 Answers7

4

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

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
Mr.Anonymous
  • 820
  • 2
  • 13
  • 22
4

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.

hammady
  • 969
  • 1
  • 13
  • 22
2

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

orkoden
  • 18,946
  • 4
  • 59
  • 50
1

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

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

Plasma
  • 2,622
  • 2
  • 20
  • 35
0

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.

Lee Probert
  • 10,308
  • 8
  • 43
  • 70
0

Take a look at this.

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

JamesB41
  • 703
  • 10
  • 20