我使用 UIAlertView 来显示包含用户名、电子邮件和密码的注册表单。但是我对 UITextField 有一个小问题:
错误:
NSInvalidArgumentException', reason: 'textFieldIndex (2) 超出了文本字段数组的范围
我的代码
// iOS7
UIAlertView *registerAlertView = [[UIAlertView alloc]
initWithTitle:@"Register"
message:@"Enter your username, email & password."
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Register", nil];
[registerAlertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
UITextField *username = [registerAlertView textFieldAtIndex:0];
UITextField *email = [registerAlertView textFieldAtIndex:1];
UITextField *password = [registerAlertView textFieldAtIndex:2];
password.secureTextEntry = YES;
[registerAlertView show];
感谢您的回答。
最佳答案
警报样式 UIAlertViewStylePlainTextInput
仅提供一个文本字段。您最多可以获得两个具有 UIAlertViewStyleLoginAndPasswordInput
样式的文本字段。
您的代码尝试使用 3 个文本字段。不支持。
如果您想要拥有三个文本字段,则需要创建或查找自定义警报 View 控件。
关于ios - UIAlertView 中的多个 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27531870/