Reputation: 12039
I am trying to capture a touch event on my UINavigationBar
. When a user taps it, I'm planning to perform an action. However, I do not seem to be able to capture touch events on this component. My code looks like this...
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self.navigationController.navigationBar action:nil];
singleTap.numberOfTapsRequired = 1;
singleTap.delegate = self;
[self.navigationController.navigationBar addGestureRecognizer:singleTap];
Whenever I tap the navigation bar, though, my selector is not called. Am I doing something wrong here? Do I need to do something special to capture touch events on this control?
Upvotes: 0
Views: 203
Reputation: 8225
Try:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething)];
singleTap.numberOfTapsRequired = 1;
//singleTap.delegate = self;
[self.navigationController.navigationBar addGestureRecognizer:singleTap];
-(void) doSomething
{
NSLog(@"doSomething");
}
Upvotes: 1