如何将多个UITextFields添加到iOS 7中的UIAlertView?

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

你不能再这样做了,iOS7中不再有UIAlertView addSubview

以下是很好的select:

IOS-定制alertview

MZFormSheetController

你的情况的一个替代方法是设置alert.alertViewStyle = UIAlertViewStylePlainTextInput;

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

在Ios7中,你需要设置,

 myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput; 

你不能在iOS7的UIAlertView上使用addSubview 。 这就是为什么它不工作,作为替代scheme,您可以使用自定义视图来做到这一点。 创build一个自定义视图,并添加文本字段,并为此添加animation。

你可以在这个链接上find自定义的alertview: Cocoa Controls

尝试这个,

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

通过m1entus尝试MZFormSheetPresentationController。

他在GitHub和CocoaPods上提供了很多例子,可以使用。