如何在iOS 7中向UIAlertView添加多个UITextFields?

3
我需要在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。


运行得非常好,http://stackoverflow.com/a/25175989/2459296 - MD SHAHIDUL ISLAM
6个回答

7

很遗憾,你不能这样做,你需要使用替代方法来检查我问题中的URL,这是唯一的方法。 - Tarek Hallak

2

对于您的情况,一种选择是设置alert.alertViewStyle = UIAlertViewStylePlainTextInput;

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


0

试试这个,

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

0
在iOS7中,您需要设置,
myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;

0

0

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接