Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS multiple text fields on a UIAlertview In IOS 7

So the new iOS 7 has come out and I'm trying to add multiple textFields and labels to the UIAlertviews. I need three. I've been trying to add them as subviews and that doesn't work anymore. I have also tried to add multiple lines with the UIAlertViewStylePlainTextInput but it only seems to return one text field.

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

like image 238
Michael Choi Avatar asked Sep 19 '13 04:09

Michael Choi


2 Answers

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

use this line to initialize your alertView

[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];

and this to grab the users input:

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

For other purposes than login view the other threads like this on: UIAlertView addSubview in iOS7

like image 99
Thorsten Niehues Avatar answered Oct 06 '22 13:10

Thorsten Niehues


You can change accessoryView to any own customContentView in a standard alert view in iOS7

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

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

Simplest illustrating 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

like image 35
malex Avatar answered Oct 06 '22 13:10

malex