Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard does not disappear after viewDidDisappear on iOS 7

In our app, there's a situation where the user enters something in a textbox and then presses the back button to go back to the master screen.

If we run that on iOS 7, the keyboard does not disappear, it just stays there. The user can still navigate through the app, but all text fields are disabled, meaning you can't enter text anywhere. The only option the user has is killing the app and starting fresh.

We tried to add resignFirstResponder messages, but that didn't help anything.

There's much code involved, and we're actively working on the issue. Meantime, has anyone experienced that problem too, and maybe found a way to make it go away?

like image 555
Bass Avatar asked Sep 19 '13 10:09

Bass


1 Answers

I had the same issue like you when I compiled the app for iOS 7 and I did the following changes:

  1. Make sure you add [textfield resignFirstResponder] before dismissing the viewController for example:

    [_passwordInput resignFirstResponder];
    [_emailInput resignFirstResponder];
    [self performSegueWithIdentifier:@"forgotPassword" sender:self];
    
  2. Just to be sure the keyboard disappears add [textfield resignFirstResponder] in viewWillDisappear for example :

    - (void) viewWillDisappear:(BOOL)animated
    {
       [_passwordInput resignFirstResponder];
       [_emailInput resignFirstResponder];
    }
    
  3. If your viewController is presented using UIModalPresentationFormSheet add this to your viewController just to make sure the textfields will respond resignFirstResponder:

    - (BOOL)disablesAutomaticKeyboardDismissal
    {
       return NO;
    }
    

In your case, override the back button action or just use viewWillDisappear to check when the user pressed the back button and then call resignFirstResponder before [super viewWillDisappear] something like this:

-(void) viewWillDisappear:(BOOL)animated 
{
   [_passwordInput resignFirstResponder];
   [_emailInput resignFirstResponder];
   [super viewWillDisappear:animated];
}
like image 113
Marius Popescu Avatar answered Nov 01 '22 19:11

Marius Popescu