0

I experiment at the moment with some alertViews. Now try to set an AlertView with two textField`s. When I click "done" it should show a Log.

At the moment, the code looks like that:

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Titel" message:@"Message" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:@"Cancel", nil]; 

The TextField should have placeholder. How do I set it up?

5
  • Look at the docs for UIAlertView. Use the provided methods to set it up to have a text field and to access the text field. Commented May 31, 2015 at 17:05
  • I found something like: alert.alertViewStyle = UIAlertViewStylePlainTextInput; And it works. But how can I add a second one? Commented May 31, 2015 at 18:46
  • Look at the other styles. Commented May 31, 2015 at 18:57
  • "UIAlertViewStyleLoginAndPasswordInput" will with "[[alert textFieldAtIndex:1] setSecureTextEntry:NO];" work for me. Thanks Commented May 31, 2015 at 19:17
  • @Nanog000 If my answer worked for you, please accept it. Commented Dec 9, 2015 at 16:48

1 Answer 1

2

Try this: it should work:

 UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Your_Title" message:@"Your_message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [av setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput]; // Alert style customization [[av textFieldAtIndex:1] setSecureTextEntry:NO]; [[av textFieldAtIndex:0] setPlaceholder:@"First_Placeholder"]; [[av textFieldAtIndex:1] setPlaceholder:@"Second_Placeholder"]; [av show]; 

You can access the values of the text fields on the alertView:clickedButtonAtIndex: of UIAlertViewDelegate.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"1 %@", [alertView textFieldAtIndex:0].text); NSLog(@"2 %@", [alertView textFieldAtIndex:1].text); } 
Sign up to request clarification or add additional context in comments.

Comments