问题
I have a modal View Controller, presented as Form Sheet on the iPad. When I send [textField resignFirstResponder], the Keyboard remains on the screen.
In the View Controller:
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
In the Navigation Controller:
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}
All this worked using iOS 6, but not with iOS 7.
回答1:
Adding the following method to the actual ViewController (rather than the NavigationController) worked for me in iOS 7.
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}
I'm calling a method that is hooked to the Text Field's Sent Event Editing Did End.
- (IBAction)KeyboardDoneKeyPressed:(id)sender
{
[sender resignFirstResponder];
}
Prior to adding the method disablesAutomaticKeyboardDismissal the keyboard would not dismiss when pressing Done.
来源:https://stackoverflow.com/questions/19237932/dismiss-keyboard-presented-in-modal-view-controller-form-sheet