【问题标题】:how to get input from UIAlertView?如何从 UIAlertView 获取输入?
【发布时间】:2009-05-19 13:53:33
【问题描述】:

我想使用 UIAlertView 将玩家姓名作为输入。是否可以在 UIAlertView 上添加 textField?

【问题讨论】:

    标签: iphone objective-c cocoa uikit


    【解决方案1】:

    从 iOS 5 开始,UIAlertView 提供:将 alertViewStyle 属性更改为以下之一:

    UIAlertViewStylePlainTextInput (1 text field)
    UIAlertViewStyleSecureTextInput (1 password field)
    UIAlertViewStyleLoginAndPasswordInput (both a text field and password field)
    

    然后使用textFieldAtIndex: 获取您想要的文本字段。这样,您甚至可以使用alertViewShouldEnableFirstOtherButton: 委托方法来启用按钮。

    【讨论】:

      【解决方案2】:

      是的,这绝对是可能的,而且它不是黑客攻击。您需要继承 UIAlertView 并将控件放入其中。由于它是一个子类,它将保持相同的外观和感觉等。

      有关详细信息,请参阅 Jeff LaMarche 的this tutorial(Apress 的《开始 iPhone 开发》的合著者)。

      【讨论】:

        【解决方案3】:

        是的,但并非没有一些黑客行为,请参阅previous question. 您必须直接操作 UIAlertView 的子视图并添加 UITextField,然后调整 UIAlertView 框架的大小。你最好创建自己的视图。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-02-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多