问题
I have a simple UIViewController derived controller which has UITextFields.
Also using IB, I placed a UIToolbar and two UIBarButtonItems. I Ctrl-Drag to add actions to the buttons.
- (IBAction)cancel:(id)sender { ... }
- (IBAction)save:(id)sender { ... }
If I run the code, the actions get called.
The problem: I wanted to implement the tap on background to resignFirstResponder paradigm, so I added a UITapGestureRecognizer on the root view:
- (void)viewDidLoad {
...
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
}
When I have the gesture recognizer, the actions of the UIBarButtonItems are not called
How can I have it both ways?
Thanks for any explanations that could help me implement this.
回答1:
I resolved the problem by adding another view and setting the gesture recognizer on that view instead of the root view.
But I still would like to know the explanation to why the gesture recognizer would "eat" the action of the UIBarButtonItem.
来源:https://stackoverflow.com/questions/11253099/uibarbuttonitems-action-is-not-called-when-in-a-view-with-a-uigesturerecognizer