【问题标题】:Can i put multiple text boxes in an alert box in ios?我可以在 ios 的警报框中放置多个文本框吗?
【发布时间】:2013-03-14 16:17:23
【问题描述】:

我可以在 iOS 的警告框上放置多个文本输入框吗?

【问题讨论】:

  • 是的,你可以。你为什么需要这个?如果您需要,可以为登录提示设置一套布局样式。
  • UIAlertView 已经支持 1 或 2 个文本字段。请阅读UIAlertView 的文档。

标签: ios alertview


【解决方案1】:

最好的解决方案是编写或使用包含您需要的文本字段的自定义警报视图。如果您只需要 1 个文本字段(或用户名/密码),您仍然可以通过设置 alertViewStyle property 来使用 UIAlertView。

已经编写了自定义警报视图,例如this one

【讨论】:

    【解决方案2】:

    是的,这是可能的。 只需将 UITextField 作为子视图添加到 UIAlertView。 为每个 UITextField 设置标签,以便稍后检索输入的文本。

        UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    
        UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
        textField1.tag=0;
        textField1.borderStyle=UITextBorderStyleRoundedRect;
        textField1.delegate=self;
    
        [alert addSubview:textField1];
    
        UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)]; 
        textField2.tag=1;
        textField2.delegate=self;
        textField2.borderStyle=UITextBorderStyleRoundedRect;
    
        [alert addSubview:textField2];
    
        [alert show];
    

    请注意,这是一种不好的做法,因为它依赖于 UIAlertView 作为 UIView 的子类。正如下面的 MusiGenesis 所指出的,它从 iOS 7 开始就无法使用。

    希望对您有所帮助。

    【讨论】:

    • 当 iOS 7(或任何版本)出现并且警报视图看起来或行为不同时会发生什么? UIAlertView 并不是要添加随机子视图。它现在可能有效,但这并不意味着它是一个好方法。
    • @rmaddy:你很有预见性 - 似乎在 iOS 7 beta 2 中,你根本无法将子视图添加到 UIAlertView
    【解决方案3】:

    如果你想要2个文本框,你可以使用登录样式,但是将第二项secureTextEntry设置为NO,参考 http://forums.macrumors.com/threads/uialertviews-with-textfields.1355954/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 2013-09-17
      • 1970-01-01
      • 2012-05-21
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      相关资源
      最近更新 更多