To hide a keyboard either [self.DateText resignFirstResponder]
or [self.view endEditing:YES]
would work.
To add a toolbar over the keyboard use [self.DateText setInputAccessoryView:yourToolBarView];
题
Currently, I am able to have my keyboard appear when I use a text field in my form. However, I'm not able to hide it. So I always need to shutdown the app and to open it back to change pages. I know there is a way to have like a toolbar to close the Keyboard when you want. However, i don't manage to see how to have this toolbar appear.
However, one of my fields enable a DatePicker View as a Keyboard instead of the natural keyboard.
- (void) initializeTextFieldInputView {
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectZero];
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.minuteInterval = 5;
datePicker.backgroundColor = [UIColor whiteColor];
[datePicker addTarget:self action:@selector(dateUpdated:) forControlEvents:UIControlEventValueChanged];
self.DateText.inputView = datePicker;
}
- (void) dateUpdated:(UIDatePicker *)datePicker {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
self.DateText.text = [formatter stringFromDate:datePicker.date];
}
解决方案
To hide a keyboard either [self.DateText resignFirstResponder]
or [self.view endEditing:YES]
would work.
To add a toolbar over the keyboard use [self.DateText setInputAccessoryView:yourToolBarView];