单元格中不可见的UITextField将userInteractionEnabled设置为No

时间:2013-02-28 16:10:59

标签: iphone ios objective-c ipad cocoa

我试图跳过用户浏览我的tableview时禁用的文本字段。但是,当它们到达可见单元格的边界时,一切都会失败,因为我试图检测文本字段是否被禁用,如果是,则再次递归调用我的方法再次导航。即。如果用户按下按钮导航到右侧,并且该文本字段被禁用,则递归再次调用右键。

似乎,禁用了可见内部单元格中的任何文本字段。一旦用户到达桌子的边缘,我就会进入无限循环,或者事情就会破裂。

这是我的代码部分,其中我进行了启用检查,如果没有进行递归调用。这真的不应该那么复杂。逻辑上我想要做的就是检测我们刚刚移动到的文本字段是否被禁用,如果是,只需再次按下相同的按钮。没什么好看的。

使用一些游戏测试

编辑,很明显,nextTextFieldSelection将返回null,尽管destinationIndexPath和newTag值是正确的。是否有可能请求indexPath不可见导致返回空值?

     //logic to move to next text field and manually scroll the tableViewbased on button input is here

    nextTextFieldSelection = (UITextField *)[[_tableView cellForRowAtIndexPath:destinationIndexPath] viewWithTag:newTag];
    if (nextTextFieldSelection.userInteractionEnabled == NO) {
        switch (arrowButton.tag) {
            case NumericKeyboardViewLeftArrow:
                currentTextField = nextTextFieldSelection;
                [self numericKeyboardView:(VS_NumericKeyboardView *)numericKeyboardView DidSelectArrowButton:(UIButton *)arrowButton];
                return;
            case NumericKeyboardViewRightArrow:
                currentTextField = nextTextFieldSelection;
                [self numericKeyboardView:(VS_NumericKeyboardView *)numericKeyboardView DidSelectArrowButton:(UIButton *)arrowButton];
                return;
            default:
                break;
        }
    }

1 个答案:

答案 0 :(得分:2)

对于不可见的单元格,

cellForRowAtIndexPath返回nil。这可能就是你进入无限循环的原因。

请参阅:http://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006943-CH3-SW16