ios black keyboard with white text appears after view change when keyboard open

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?

Answers


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];
        }
}

Need Your Help

I want to open an external link inside my jquery mobile app (phongap build) but all external links open in browser

android jquery-mobile phonegap-build

this is my first time using phonegap build and I'm having trouble opening external links inside my app. I'm using jquery mobile and phonegap build to publish an android app. Before the the update...

Making data persistent in android

android persistence

In my application,there are some application specific settings, which should be available to me , next time when my application starts up.