2015-05-31 5 views
0

Я экспериментирую на данный момент с некоторыми alertViews. Теперь попробуйте установить AlertView с двумя текстовыми полями. Когда я нажимаю «done», он должен показывать журнал.UIAlertView с textField

На данный момент, код выглядит следующим образом:

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

текстовое поле должно иметь заполнитель. Как мне настроить его?

+0

Посмотрите на документы для 'UIAlertView'. Используйте предоставленные методы, чтобы настроить его на наличие текстового поля и доступ к текстовому полю. – rmaddy

+0

Я нашел что-то вроде: alert.alertViewStyle = UIAlertViewStylePlainTextInput; И это работает. Но как я могу добавить второй? – Nanog000

+0

Посмотрите на другие стили. – rmaddy

ответ

2

Попробуйте это: он должен работать:

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

Вы можете получить доступ к значениям текстовых полей на alertView:clickedButtonAtIndex: из UIAlertViewDelegate.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    NSLog(@"1 %@", [alertView textFieldAtIndex:0].text); 
    NSLog(@"2 %@", [alertView textFieldAtIndex:1].text); 
} 
Смежные вопросы