6

I am using a "dark" style keyboard for my standard TextField. This is for a login textfield, or "forget my password" textfield, where the user enters some info, submits it, and if it succeeds they are sent to another View, usually by a standard navigation controller popViewControllerAanimated:. An AlertView may appear in between.

The problem I've seen a lot is that the keyboard is open, a normal "dark" gray color, and then the user clicks Submit, an alert view may appear, and when dismissing that the the view shifts to the next screen with the previous keyboard going off screen. On the new screen another default style keyboard may or may not slide up and then disappear (without a textfield being focused on even!). Then, when clicking into another textfield, or going back to the previous view and clicking into a textfield, this black keyboard with white keys appears erroneously. It continues to appear for textfields until something is able to jar it back to the normal dark gray after a few clicks.

I've tried to dismiss the original keyboard before the popViewController happens, in various ways, but it doesn't seem to help. If the AlertView appears inbetween, I tied the popViewController to the delegate action on clicking the AlertView button. The keyboard usually doesn't disappear fast enough to leave before the push. A delay doesn't help it.

EDIT: The alertview seems to be a definite culprit here, interfering with the pop and keyboard somehow.

-(BOOL) textFieldShouldReturn:(UITextField *)textField{
    [textfield resignFirstResponder];
    [self.view endEditing:YES];
    return YES;
}

-(IBAction)submitRequest {
    [textfield resignFirstResponder];
    [self.view endEditing:YES];

    // make API call, if call succeeds run this block {
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"..."
                                                message:@"..."
                                               delegate:delegate
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil, nil];
          dispatch_async(dispatch_get_main_queue(), ^{
            [alert show];
          });         
    // }
}

// delegate after alert OK is pressed
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  [self.navigationController popViewControllerAnimated:YES];
}

How can I avoid this black/white keyboard?

enter image description here

Miro
  • 5,307
  • 2
  • 39
  • 64
  • "I've tried to dismiss the original keyboard before the pushViewController happens, in various ways, but it doesn't seem to help" Right, but you get a notification when the keyboard _has_ disappeared, so why don't you start the view controller transition then? – matt Mar 26 '16 at 01:19
  • Is this a custom keyboard? It doesn't seem like an Apple keyboard to me... – Blip Mar 26 '16 at 01:20
  • I am using the standard "dark" standard gray keyboard throughout the app. It's a darker gray than the default light gray one. but it isn't a black one like this. I don't use custom keyboards. – Miro Mar 26 '16 at 01:52
  • Just adding a comment to say that I've seen this too, and it's a pretty annoying bug. Haha @Blip, no it doesn't look like an Apple keyboard at all, it's a bug. – ndbroadbent Apr 29 '16 at 21:23
  • Can anybody provide solution for iOS 9? My project having this issues even after compiled in Xcode 7.3.1. – Mohd Sadham Jun 21 '16 at 09:30

1 Answers1

3
Try using the below code. It works fine for iOS 8 and below version

    if (IS_OS_8_OR_LATER) {
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction *cancelAction = [UIAlertAction
                                       actionWithTitle:B_title
                                       style:UIAlertActionStyleCancel
                                       handler:^(UIAlertAction *action)
                                       {
                                           [self.navigationController popViewControllerAnimated:YES];

                                       }];
        [alertVC addAction:cancelAction];
        [self presentViewController:alertVC animated:YES completion:nil];
        }
        else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        }
}
jbchitaliya
  • 211
  • 2
  • 13