ios - UIAlertView 中的多个 UITextField

标签 ios objective-c ios7 uitextfield uialertview

我使用 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/

相关文章:

ios - 来自 iOS 的 Django HTTP Post 请求

ios - 无法在包 : 'NSBundle ERROR 中加载 NIB

ios - 如何键入自动完成中显示的方法名称的下一部分?

iphone - 开源 Objective-C 语法荧光笔?

ios - 在 iOS 7 中显示键盘时出现问题 'Resizing' UITextView

php - iOS 7 服务器收据验证 (php)

ios7 - 如果无法访问 UIWebView 的运行时,为什么要在 iOS7 中使用 JavaScriptCore?

ios - BarButtonItems 是如何添加到 NavigationBar 的?

ios - 具有 2 列 swift 的表格布局

iphone - 我如何显示 UIViewAnimationOptionTransitionCurl (MapCurl)?