我现在用一些alertViews进行实验。现在尝试使用两个textField来设置AlertView。当我点击“完成”时,它应该显示一个日志。
目前,代码看起来像这样:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Titel" message:@"Message" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:@"Cancel", nil];
TextField应该有占位符。我该如何设置?
答案 0 :(得分: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);
}