I try to hide keyboard on iPad but I don't know why resignFirstResponder don't work. But popToRoot has work well.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSString *desc = [NSString stringWithFormat:@"%@",[descTF text]];
[textField resignFirstResponder];
[self.navigationController popToRootViewControllerAnimated:YES];
return YES;
}
So Could you guide me what should I do please ??
Is this field inside a UIModalPresentationFormSheet
? If so, it's a known issue that you can not dismiss the keyboard programmatically until the view controller gets dismissed.
UPDATE: according to this thread from the Apple Developer Forums, a possible workaround for this is to present the sheet view control from inside a navigation controller subclass that implements the disablesAutomaticKeyboardDismissal method. So something like:
MyViewController *myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
CustomNavigationController *navController = [[CustomNavigationController alloc] initWithRootViewController:myViewController];
theNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:theNavigationController animated:YES];
To follow up on samvermette's answer, if it is inside a UIModalPresentationFormSheet
you can now override the disablesAutomaticKeyboardDismissal
method to get the behavior you desire. Add the following method to your class and the UITextFields
and UITextViews
will respond to resignFirstResponder.
- (BOOL)disablesAutomaticKeyboardDismissal {
return NO;
}
You should never have occasion to send -resignFirstResponder
. What you should do is just send -endEditing:YES
to the view in question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With