user4933792
user4933792

Reputation:

UIAlertView with textField

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?

Upvotes: 0

Views: 2138

Answers (1)

Jessica
Jessica

Reputation: 9830

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);
}

Upvotes: 2

Related Questions