3

I need to add Multiple UITextField on a UIAlertView in iOS 7?

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

in IOS 6 no problem but in IOS 7 it not show UITextField

mmackh
  • 3,550
  • 3
  • 35
  • 51
Luna
  • 113
  • 1
  • 6

6 Answers6

7

You can't do this any more, there is no addSubview for UIAlertView any more in iOS7.

Below are good alternative:

ios-custom-alertview

MZFormSheetController

Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
2

One alternative in your case is to set alert.alertViewStyle = UIAlertViewStylePlainTextInput;

This will add a text field for you. You can access it in the UIAlertView delegate callback by using UITextField *textField = [alertView textFieldAtIndex:0];.

iVenky
  • 441
  • 1
  • 4
  • 14
0

In Ios7, you need to set,

myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
karthika
  • 4,085
  • 3
  • 21
  • 23
0

You can't use addSubview on UIAlertView in iOS7. That's why it is not working, as an alternative you can use a custom view for doing this. Create a custom view and add textfield to it and add animations for this.

You can find customized alertview's on this link: Cocoa Controls

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
0

Try this,

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];
Neenu
  • 6,848
  • 2
  • 28
  • 54
0

Try MZFormSheetPresentationController by m1entus.

He provides a number of examples on GitHub and CocoaPods and they're ready to use.

Lukasz Czerwinski
  • 13,499
  • 10
  • 55
  • 65