user3785463
user3785463

Reputation: 119

How to keep iOS keyboard opened while alert showing?

I have a textfield in my iOS application and sometimes I need to show alert messages (UIAlertView) for different reasons (for example, too many characters etc.).

When I show the alert the keyboard hiding. How can I keep keyboard opened while alert message is showing? Or maybe I missed something?

The way I use alerts:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry"
                                                        message:@"Too many characters."
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];

[alert show];

Upvotes: 1

Views: 754

Answers (3)

Steve Wilford
Steve Wilford

Reputation: 9002

I need to show alert messages (UIAlertView) for different reasons (for example, too many characters etc.)

This would be terrible UX, do it a different way such as showing a validation label near to the text field.

Something like what is suggested in this article:

enter image description here

Upvotes: 2

Massimo Polimeni
Massimo Polimeni

Reputation: 4906

Call [textfield becomeFirstResponder] after your [alert show] just like this:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry"
                                                        message:@"Too many characters."
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];

[alert show];
[textfield becomeFirstResponder]

Upvotes: 0

Abhinav
Abhinav

Reputation: 38152

Well, this is something Apple introduced with iOS 8 and it makes sense as well. When alert is shown on screen you do not want user to get diverted with things like keyboard.

However, if you still want to show it then when user tap on UIAlertView button you can call [textfield becomeFirstResponder] on your text field or text view.

Upvotes: 1

Related Questions