找到你要的答案

Q:How to keep iOS keyboard opened while alert showing?

Q:如何保持iOS键盘打开,警报显示?

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

我在我的iOS应用程序有时需要显示警报消息的文本框(UIAlertView)不同的原因(例如,太多的人物等)。

当我显示警报时键盘隐藏。在警报信息显示时,如何保持键盘打开?或者我错过了什么?

我使用警报的方式:

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

[alert show];
answer1: 回答1:

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:

我需要显示警报消息(UIAlertView)不同的原因(例如,太多的人物等)

这将是很糟糕的用户体验,做一个不同的方式,如显示验证标签靠近文本字段。

这篇文章中建议的东西:

answer2: 回答2:

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.

嗯,这是苹果推出iOS 8和它使意识等。当屏幕上显示警报时,你不希望用户被键盘之类的东西分心。

然而,如果你还想给它当用户点击按钮可以调用UIAlertView [文本]你becomefirstresponder文本字段或文本视图。

answer3: 回答3:

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]

叫[文本becomefirstresponder ]后[显示]警惕你这样:

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

[alert show];
[textfield becomeFirstResponder]
ios  objective-c  uialertview  ios9