Multiple iOS text fields in UIAlertview on iOS 7

So, the new iOS 7 has appeared, and I'm trying to add some text fields and shortcuts to UIAlertviews. I need three. I tried to add them as subzones, and this no longer works. I also tried adding a few lines with UIAlertViewStylePlainTextInput, but it seems to only return a single text field.

I need to add shortcuts to show them what to enter. Is there a way to accomplish this task with the new iOS 7?

+8
ios uitextfield textfield uialertview
Sep 19 '13 at 4:10
source share
3 answers

The only solution I found using UIAlertView with more than one text box in iOS7 is for login only.

use this line to initialize alertView

[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput]; 

and this is to capture user input:

 user = [alert textFieldAtIndex:0].text; pw = [alert textFieldAtIndex:1].text 

For purposes other than logging in, they see other threads like this: UIAlertView addSubview in iOS7

+14
Sep 27 '13 at 13:13
source share

You can change the accessory for any of your own customContentView in the standard warning view in iOS7

 [alertView setValue:customContentView forKey:@"accessoryView"]; 

Note that you must call this before [alertView show].

The simplest illustrative example:

 UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil]; UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]; v.backgroundColor = [UIColor yellowColor]; [av setValue:v forKey:@"accessoryView"]; [av show]; 

enter image description here

+12
Jan 11 '14 at 20:28
source share

If you want to add only two text fields to your UIAlertView , you can use UIAlertViewStyleLoginAndPasswordInput and change the text fields as follows:

 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Some Title" message:@"Some Message." delegate:self cancelButtonTitle:@"Okay" 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]; 

Then in the UIAlertView delegate, you can just get the text using:

 text1 = [alert textFieldAtIndex:0].text; text2 = [alert textFieldAtIndex:1].text; 
+10
Oct 06 '14 at 10:20
source share



All Articles