我可以在iOS的警告框中放置多个文本输入框吗?
答案 0 :(得分:2)
最佳解决方案是编写或使用包含所需文本字段的自定义警报视图。如果您只需要1个文本字段(或用户名/密码),则仍可以通过设置alertViewStyle property来使用UIAlertView。
已经编写了自定义警报视图,例如this one。
答案 1 :(得分:1)
是的,这是可能的。 只需将UITextField作为子视图添加到UIAlertView即可。 为每个UITextField设置标记,以便稍后检索输入的文本。
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
textField1.tag=0;
textField1.borderStyle=UITextBorderStyleRoundedRect;
textField1.delegate=self;
[alert addSubview:textField1];
UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
textField2.tag=1;
textField2.delegate=self;
textField2.borderStyle=UITextBorderStyleRoundedRect;
[alert addSubview:textField2];
[alert show];
请注意,这是不好的做法,因为它依赖于UIAlertView是UIView的子类。正如下面的MusiGenesis所指出的那样,从iOS 7开始它将不起作用。
希望有所帮助。
答案 2 :(得分:0)
如果你想要2个文本框,可以使用登录样式,但是将第二个项目secureTextEntry设置为NO,参考 http://forums.macrumors.com/threads/uialertviews-with-textfields.1355954/