【问题标题】:textFieldIndex (0) is outside of the bounds of the array of text fieldstextFieldIndex (0) 超出了文本字段数组的范围
【发布时间】:2014-06-14 17:32:11
【问题描述】:

我已经四处寻找答案,但没有找到任何接近的答案。

以下代码:

UIAlertView *welcome = [[UIAlertView alloc] initWithTitle:@"Welcome"
                                                  message:@"Please Enter Your Credentials to Proceed"
                                                 delegate:self
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
[welcome show];

给出以下错误

textFieldIndex (0) 超出了文本字段数组的范围

如果我将alertView 类型更改为UIAlertViewStylePlainTextInput,那么它可以工作,但我不知道为什么!

任何帮助将不胜感激。

【问题讨论】:

    标签: ios objective-c cocoa-touch uialertview


    【解决方案1】:

    您在没有或不应该有textFieldalertView 对象上调用-textFieldAtIndex:

    检查以下内容:

    [welcome textFieldAtIndex:0];
    

    或者...

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        //...
        [alertView textFieldAtIndex:0];
        //...
    }
    

    这可能是如果您使用多个 alertView 对象并且尚未处理完成的案例处理以将具有 textField 和另一个 alertViewalertView 对象的实现分开有一个textField

    【讨论】:

    • 事实上你是对的。我在其他地方也有这个:[[alertView textFieldAtIndex:0] text];那么处理多个alterviews的最佳方法是什么?
    • 谢谢排序:我添加了[alert setTag:1];到有问题的 AlertView 然后使用 if ([alertView tag] == 1) 以确保仅在需要时调用它。标记所有警报视图是一种好的做法吗?
    • @user3740845 :是的,标签......这就是通常的做法。你在正确的轨道上:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多