Plasma
Plasma

Reputation: 2912

NSInvalidArgumentException - Unrecognised Selector Sent to instance

I know this is going to be something really stupid, but I've been trying to figure it out for 2 days now, so am conceding defeat.

I am trying to implement a Double Tap Gesture recogniser on a NavBar. However when double tapping it I get the following crash....

2014-10-11 13:05:01.317 Gesture[4811:152609] -[UINavigationBar navigationBarDoubleTap:]: unrecognized selector sent to instance 0x78818150
2014-10-11 13:05:01.321 Gesture[4811:152609] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationBar navigationBarDoubleTap:]: unrecognized selector sent to instance 0x78818150'

Its a plain View Controller, with a Navigation Bar added to the view. I instantiate the gesture recogniser with this in ViewDidLoad ...

.h
IBOutlet UINavigationBar    *navBar;
UITapGestureRecognizer      *tapRecon;

.m (viewDidLoad)
//Add double tap gesture to Navbar For Auto Refresh
tapRecon = [[UITapGestureRecognizer alloc]
            initWithTarget:navBar action:@selector(navigationBarDoubleTap:)];
tapRecon.numberOfTapsRequired = 2;
[navBar addGestureRecognizer:tapRecon];

The DoubleTap Method is

(void)navigationBarDoubleTap :(id) sender {
    NSLog(@"Sender: %@", sender);
}

I've wired the navBar to my UINavigationBar, and set its delegate to the View. I've also tried the method with and without the (id)sender.

Many Thanks

Plasma

Upvotes: 0

Views: 128

Answers (1)

Sandeep
Sandeep

Reputation: 21154

tapRecon = [[UITapGestureRecognizer alloc]
            initWithTarget:self action:@selector(navigationBarDoubleTap:)];
tapRecon.numberOfTapsRequired = 2;
[navBar addGestureRecognizer:tapRecon];

Upvotes: 2

Related Questions