Luna
Luna

Reputation: 113

How to add multiple UITextFields to a UIAlertView in iOS 7?

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

Upvotes: 3

Views: 5936

Answers (6)

Lukasz Czerwinski
Lukasz Czerwinski

Reputation: 15432

Try MZFormSheetPresentationController by m1entus.

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

Upvotes: 0

Stive
Stive

Reputation: 6888

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

Upvotes: 0

Midhun MP
Midhun MP

Reputation: 107131

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

Upvotes: 0

iVenky
iVenky

Reputation: 441

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

Upvotes: 2

Tarek Hallak
Tarek Hallak

Reputation: 18470

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

Upvotes: 7

karthika
karthika

Reputation: 4091

In Ios7, you need to set,

myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;

Upvotes: 0

Related Questions