Randomblue
Randomblue

Reputation: 116283

Show UIAlertView and keyboard simultaneously

It looks like iOS 8 has a bug where alerts with text input do not show the keyboard. I have tried this hack.

The problem with the hack is that first the alert appears, and only afterwards does the keyboard appear. This causes the alert to "jump up" to make space for the keyboard.

How can I have a UIAlertView with text input, where the keyboard appears immediately?

(Note: For an example of what I want, go to Voice Memos, record a new memo, save, and you'll be prompted to enter a name with a UIAlertView with text input. There, the keyboard appears at the same time as the UIAlertView.)

Upvotes: 3

Views: 1289

Answers (2)

Ravi Kumar
Ravi Kumar

Reputation: 1366

//ctrl+k to appear keyboard and ios8 keyboard appearing simultaneously issue would solve by this...

UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"" message:@"Registration Successfully" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction * ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){

                            // [self.view endEditing:YES];
                            // [self.navigationController popToRootViewControllerAnimated:YES];

                         }];
[alert addAction:ok];
[self presentViewController:alert animated:YES completion:nil];

Upvotes: 0

Vinay Jain
Vinay Jain

Reputation: 1661

I am not sure this will perfectly solve the problem of keyboard and alertView appearing simultaneously. But I would recommend you to use the newer api. I am posting this as an answer as its difficult to put code into comments.

For some reasons UIAlertView has been deprecated in iOS 8. Instead of using the UIAlertView you should use the UIAlertController with style UIAlertControllerStyleAlert. Present it and then open keyboard.

UIAlertController *alert = [UIAlertController alertControllerWithTitle:yourTitle message:yourMessage preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];

Since the alert now is shown as UIViewController the keyboard won't shift the alert box upside.

Upvotes: 5

Related Questions