【问题标题】:How to add multiple UITextFields to a UIAlertView in iOS 7?如何在 iOS 7 中向 UIAlertView 添加多个 UITextField?
【发布时间】:2013-09-30 09:18:59
【问题描述】:

我需要在 iOS 7 的 UIAlertView 上添加多个 UITextField?

 myAlertView = [[UIAlertView alloc] initWithTitle:@"Enter Your Detail" message:@"\n\n\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Register",nil];
txtEmail = [[UITextField alloc] initWithFrame:CGRectMake(30, 40, 220, 25)];
txtEmail.placeholder = @"email address";
txtFirstName = [[UITextField alloc] initWithFrame:CGRectMake(30, 70, 220, 25)];
txtFirstName.placeholder = @"first Name";
txtSurname = [[UITextField alloc] initWithFrame:CGRectMake(30, 100, 220, 25)];
txtSurname.placeholder = @"surname";
[myAlertView addSubview:txtEmail];
[myAlertView addSubview:txtFirstName];
[myAlertView addSubview:txtSurname];

[myAlertView show];

在 IOS 6 中没有问题,但在 IOS 7 中它不显示 UITextField

【问题讨论】:

标签: iphone ios


【解决方案1】:

你不能再这样做了,在 iOS7 中已经没有 addSubviewUIAlertView 了。

以下是不错的选择:

ios-custom-alertview

MZFormSheetController

【讨论】:

  • 不幸的是你不能,你需要在我的问题中使用替代检查网址,这是唯一的方法。
【解决方案2】:

在您的情况下,另一种选择是设置 alert.alertViewStyle = UIAlertViewStylePlainTextInput;

这将为您添加一个文本字段。您可以使用UITextField *textField = [alertView textFieldAtIndex:0]; 在 UIAlertView 委托回调中访问它。

【讨论】:

    【解决方案3】:

    在ios7中,需要设置,

    myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    

    【讨论】:

      【解决方案4】:

      在 iOS7 中,您不能在 UIAlertView 上使用 addSubview。 这就是它不起作用的原因,作为替代方案,您可以使用自定义视图来执行此操作。 创建一个自定义视图并向其添加文本字段并为此添加动画。

      您可以在此链接上找到自定义的警报视图:Cocoa Controls

      【讨论】:

        【解决方案5】:

        试试这个,

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Forgot Password" message:@"Please enter the email ID associated with your Hngre account." delegate:self cancelButtonTitle:@"Here you go" otherButtonTitles:@"No, thanks", nil];
        alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
        [alert textFieldAtIndex:1].secureTextEntry = NO; //Will disable secure text entry for second textfield.
        [alert textFieldAtIndex:0].placeholder = @"First Placeholder"; //Will replace "Username"
        [alert textFieldAtIndex:1].placeholder = @"Second Placeholder"; //Will replace "Password"
        [alert show];
        

        【讨论】:

          【解决方案6】:

          试试 m1entus 的MZFormSheetPresentationController

          他在 GitHub 和 CocoaPods 上提供了许多示例,它们已经可以使用了。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2013-09-16
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-09-04
            • 1970-01-01
            相关资源
            最近更新 更多