【问题标题】:In UIAlertView trying to view two textfield. Its showing error bounds of the array of text fields iOS7在 UIAlertView 试图查看两个文本字段。它显示文本字段数组iOS7的错误范围
【发布时间】:2014-04-21 07:57:28
【问题描述】:

您好,我正在尝试查看 UIAlertView 中的两个文本字段,但显示错误。我已经使用下面的代码来查看文本字段。

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Hello!"
                                                     message:@"Please enter your details:"
                                                    delegate:self
                                           cancelButtonTitle:@"Continue"
                                           otherButtonTitles:nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;

    UITextField * name = [alert textFieldAtIndex:0];
    name.keyboardType = UIKeyboardTypeAlphabet;
    name.placeholder = @"Enter your name";

    UITextField * phone = [alert textFieldAtIndex:1];
    phone.keyboardType = UIKeyboardTypeNumberPad;
    phone.placeholder = @"Enter your phone";

    [alert show];
    [alert release];
}

我已经使用上面的代码查看了两个文本文件,但我越来越喜欢了。 'textFieldIndex (1) 超出了文本字段数组的范围'

请告诉我我在上面的代码中哪里做错了,请告诉我要解决这个问题。

【问题讨论】:

标签: ios objective-c ios7 uialertview


【解决方案1】:

查看UIAlertView.h文件

/* 在索引处检索文本字段 - 引发 NSRangeException 时 textFieldIndex 超出范围。索引 0 处的字段将是 第一个文本字段(单个字段或登录字段),该字段位于 索引 1 将是密码字段。 */

- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);

这样做:

alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

UITextField * name = [alert textFieldAtIndex:0];
name.keyboardType = UIKeyboardTypeAlphabet;
name.placeholder = @"Enter your name";

UITextField * phone = [alert textFieldAtIndex:1];
phone.secureTextEntry = NO;
phone.keyboardType = UIKeyboardTypeNumberPad;
phone.placeholder = @"Enter your phone";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 2014-04-08
    • 2019-09-15
    • 2013-08-28
    相关资源
    最近更新 更多