Keyboard will appeared automatically in ios 8.3 while displaying alertview or alertcontroller

In my case i tried hiding keyboard, before showing alert, so it will not save keyboard in memory to present it again after dismissing it self.

for that you just need to dismiss keyboard which will take default animation time to hide, only then you should present alert view then it will not save that keyboard.

you must put around .6 second gap in hiding keyboard and presenting alert

  [YOUR_TEXT resignFirstResponder];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{


                    _alertVw = [[UIAlertView alloc] initWithTitle:@"" message:@"message." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

                    [_alertVw show];
});

Yep, it's strange.

But since iOS 8, I suggest to use the UIAlertController instead of UIAlertView.

Replace your code with this one:

- (IBAction)MethodShowAlert:(id)sender
{

    [tmptxtField resignFirstResponder];

    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"Check Alert textField"
                                                                              message:@"keyboard should not be open"
                                                                       preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                            style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction *action) {
                                                              [self showCustomAlertWithTitle:@"Now Check"];
                                                          }];

    [alertController addAction:cancelAction];

    [self presentViewController:alertController animated:YES completion:nil];
}


-(void)showCustomAlertWithTitle:(NSString *)title{

    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:title
                                                                              message:nil
                                                                       preferredStyle:UIAlertControllerStyleAlert];

    [self presentViewController:alertController animated:YES completion:nil];
}

The keyboard will not show after the click on the button.


This was a change in behaviour introduced in iOS 8.3. Try downloading the iOS 8.2 simulator and you will see the old behaviour.

The result of my analysis was the following:

  1. When an alert is shown, it saves the currently showing keyboard.
  2. When an alert has completed the dismiss animation, it restores the previously saved keyboard.

So in -[id<UIAlertViewDelegate> alertView:clickedButtonAtIndex:], you are between those states. So what happens with two Alerts that are shown at the same time:

  1. Show Alert1. Save visible keyboard. Hide keyboard.
  2. User taps on alert.
  3. Show Alert2. Save that there is no keyboard.
  4. Alert1 completes dismiss animation. Restore saved keyboard. Keyboard is visible.
  5. User taps on alert.
  6. Alert2 is dismissed. Restore that there is no keyboard. Hide keyboard.

My recommendation is to use a UIAlertViewDelegate method that is called after the dismiss animation completes and show the next alert then.