how to dismiss keyboard?

In my app, I press a button and it pulls up a modal presentation sheet (for iPad). Within this modal view I have a scrollview within my main view, and 1 text field within my scroll view.

view controller
    view
        scrollview
            text field

Nothing I have tried resigns the keyboard and I don't know why. The only thing that happens is the blinking cursor in the textfield goes away. My class is the delegate for the scrollview and text fields. Here is what I have tried:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.titleTextField resignFirstResponder];
    [self.titleTextField endEditing:YES];
    [self.view endEditing:YES];
    [self.view resignFirstResponder];
    [self.scrollView endEditing:YES];
    [self.scrollView resignFirstResponder];
}

The method does get called, but the keyboard doesn't go away. Can anyone help me or at least tell me why?

Here is how I present this modalpresentation view:

(it comes from a tableviewcontroller)

didSelectRowAtIndexPath

EditVideo *targetController = [self.storyboard instantiateViewControllerWithIdentifier:@"editVideo"];

        targetController.delegate = self;

        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:targetController];

        navigationController.modalPresentationStyle = UIModalPresentationFormSheet;

        [self presentViewController:navigationController animated:YES completion:nil];

        [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

On the iPad for any any non-fullscreen presented ViewController, you must implement -(BOOL)disablesAutomaticKeyboardDismissal to return NO to dismiss the keyboard.

- (BOOL)disablesAutomaticKeyboardDismissal
{
    return NO;
}

Once that is implemented, you can call [self.view endEditing:YES]; .

Edit: The other common cause of this problem is returning NO from - (BOOL)textFieldShouldEndEditing:(UITextField *)textField . Implement the method in the UITextFieldDelegate and have it return YES unconditionally to prove that it is not a factor.

链接地址: http://www.djcxy.com/p/7704.html

上一篇: 关闭UISearchBar键盘而不影响取消按钮

下一篇: 如何解雇键盘?