Search code examples
objective-cipaduinavigationcontrollerkeyboard

Dismiss Keyboard When Leaving FormSheet View?


I have a UINavigationController which uses Form Sheet views and I have viewController 1 which pushes viewController2.

viewController2 has a UITextField and the keyboard pops up, great. However upon popping this view and going back to viewController1 the keyboard stays up and I just can't get it to dismiss.

I just want the keyboard to dismiss when returning to viewController1.


Solution

  • In your second view controller in the viewWillDisappear: method do this:

    - (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
        [textField resignFirstResponder];
    }
    

    This will take the focus from the text field and that results in the keyboard being dismissed.