Mic*_*hoi 8 textfield uitextfield uialertview ios
所以新的iOS 7已经问世,我正在尝试为UIAlertviews添加多个textFields和标签.我需要三个.我一直在尝试将它们添加为子视图,这不再适用.我还尝试使用UIAlertViewStylePlainTextInput添加多行,但它似乎只返回一个文本字段.
我需要添加标签以向他们展示要输入的内容.有没有办法用新的iOS 7完成这项任务?
Tho*_*ues 14
我发现在iOS7中使用带有多个文本字段的UIAlertView的唯一解决方案仅用于登录.
使用此行初始化alertView
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
Run Code Online (Sandbox Code Playgroud)
这样可以获取用户输入:
user = [alert textFieldAtIndex:0].text;
pw = [alert textFieldAtIndex:1].text
Run Code Online (Sandbox Code Playgroud)
除了登录视图之外的其他目的,其他线程如下:iOS7中的UIAlertView addSubview
mal*_*lex 12
您可以更改accessoryView的任何自己customContentView在iOS7标准警报视图
[alertView setValue:customContentView forKey:@"accessoryView"];
Run Code Online (Sandbox Code Playgroud)
请注意,您必须在[alertView show]之前调用它.
最简单的说明示例:
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];
Run Code Online (Sandbox Code Playgroud)

ZeM*_*oon 11
如果您只想添加两个文本字段UIAlertView,可以使用UIAlertViewStyleLoginAndPasswordInput和修改文本字段,如下所示:
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Some Title" message:@"Some Message." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"No, thanks", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert textFieldAtIndex:1].secureTextEntry = NO; //Will disable secure text entry for second textfield.
[alert textFieldAtIndex:0].placeholder = @"First Placeholder"; //Will replace "Username"
[alert textFieldAtIndex:1].placeholder = @"Second Placeholder"; //Will replace "Password"
[alert show];
Run Code Online (Sandbox Code Playgroud)
然后,在UIAlertView委托中,您可以使用以下命令获取文本:
text1 = [alert textFieldAtIndex:0].text;
text2 = [alert textFieldAtIndex:1].text;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15788 次 |
| 最近记录: |