Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resignFirstResponder Don't work?

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 ??

like image 769
crazyoxygen Avatar asked Jul 28 '11 02:07

crazyoxygen


3 Answers

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];
like image 180
samvermette Avatar answered Oct 23 '22 16:10

samvermette


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;
}
like image 7
Rob Jones Avatar answered Oct 23 '22 16:10

Rob Jones


You should never have occasion to send -resignFirstResponder. What you should do is just send -endEditing:YES to the view in question.

like image 1
NSResponder Avatar answered Oct 23 '22 16:10

NSResponder