【问题标题】:How to keep iOS keyboard opened while alert showing?如何在显示警报时保持 iOS 键盘打开?
【发布时间】:2015-10-08 10:21:23
【问题描述】:

我的 iOS 应用程序中有一个文本字段,有时我需要显示警报消息 (UIAlertView) 出于不同的原因(例如,字符太多等)。

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

我使用警报的方式:

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

[alert show];

【问题讨论】:

    标签: ios objective-c uialertview ios9


    【解决方案1】:

    出于不同的原因(例如,字符过多等),我需要显示警报消息 (UIAlertView)

    这将是糟糕的用户体验,请以不同的方式进行,例如在文本字段附近显示验证标签。

    类似于this article 中的建议:

    【讨论】:

      【解决方案2】:

      嗯,这是 Apple 在 iOS 8 中引入的东西,它也很有意义。当屏幕上显示警报时,您不希望用户被键盘之类的东西转移。

      但是,如果您仍想显示它,那么当用户点击 UIAlertView 按钮时,您可以在文本字段或文本视图上调用 [textfield becomeFirstResponder]

      【讨论】:

        【解决方案3】:

        在你的[alert show] 之后调用[textfield becomeFirstResponder],就像这样:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-04-18
          • 2016-01-21
          • 1970-01-01
          • 1970-01-01
          • 2015-04-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多