Reputation: 2352
I'm having a bit of a problem when testing my app in iOS5/5.1. My IBAction from a button press just simply isn't getting called. I read somewhere that it could be because of gesture recognisers. I have this code which dismisses the keyboard when the user taps anywhere on the screen, and I think this might be the culprit. I also have a similar code in another screen but I can't even reach it to see if it's bugged similarly.
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[tapRecognizer setDelegate:(id)self];
[tapRecognizer setNumberOfTapsRequired:1];
[self.view addGestureRecognizer:tapRecognizer];
And here is the function.
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
[self.searchBar resignFirstResponder];
}
How can I prevent this glitch from happening without losing the ability to dismiss the keyboard with a tap?
Regards, Mike.
Upvotes: 3
Views: 911
Reputation: 6806
Is the gesture recognizer recognising the tap and thus not delivering it to the button, which is a subview of the view to which the gesture recognizer is attached? You could try deleting the gesture recognizer once handleSingleTap
has been called.
Upvotes: 4