Is there a way to add a cancel button to the keyboard displayed for UITextField
? Looking over the UITextInputTraits
Protocol Reference, I could not
I just dropped a UIToolbar
into my view controller in Interface Builder, then:
@property IBOutlet UIToolbar *keyboardAccessory;
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// this is so I can edit it in Interface Builder, but it doesn't show in the view
[keyboardAccessory removeFromSuperview];
}
-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField {
textField.inputAccessoryView = keyboardAccessory;
return YES;
}
-(IBAction) pressedCancelButton {
[self.view endEditing:YES];
}
Voila!