UIBarItem does not respond to clicks inside UIToolbar which is setup as inputAccessoryView on a UITextField.
The button does not show click animation when I try to click it, callback does not get called. My setup looks like:
@interface MyViewController()
@property (weak, nonatomic) IBOutlet UITextField *closeDateTextField;
@property (strong, nonatomic) UIToolbar * datePickerToolbar;
@end
I setup toolbar with button:
- (void)viewDidLoad {
self.datePickerToolbar = [[UIToolbar alloc] init];
UIBarButtonItem * doneBtn =
[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(hidePicker:)];
add button to toolbar and set toolbar as inputAccessoryView
of UITextField
:
[self.datePickerToolbar setItems:@[doneBtn] animated:NO];
self.closeDateTextField.inputAccessoryView = self.datePickerToolbar;
}
When I click on closeDateTextField
the keyboard appears with a Done
button in toolbar but the button does not respond to click, the hidePicker:
does not get called.
- (void)hidePicker:(id)sender {
[self.closeDateTextField resignFirstResponder];
}
Any idea what I'm doing wrong?