2013-09-30 41 views
3

我需要在iOS 7的UIAlertView上添加多个UITextField?如何将多个UITextFields添加到iOS 7中的UIAlertView?

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

+0

只是作为魅力http://stackoverflow.com/a/25175989/2459296 – Salim

回答

7

你不能这样做任何更多的,有没有addSubviewUIAlertView更多在iOS7中。

下面是很好的选择:

ios-custom-alertview

你的情况MZFormSheetController

+0

你能告诉我我怎么解决它? – Luna

+0

不幸的是,你需要使用替代检查我的问题中的网址,这是唯一的方法。 – null

0

在Ios7,您需要设置,

myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput; 
+0

谢谢,我试试这个,但它只是显示文本域默认 – Luna

2

一种替代方法是设置 alert.alertViewStyle = UIAlertViewStylePlainTextInput;

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

+0

谢谢,我试过了 – Luna

0

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

您可以在此链接上找到定制alertview的:Cocoa Controls

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