2013-02-28 49 views
0

我想,当用户浏览我的tableview跳过被禁用的文本字段。但是,当它们到达可见单元格的边界时,所有内容都会因为尝试检测文本字段是否被禁用而出现问题,如果是,则再次递归调用我的方法以再次导航。即。如果用户按下按钮导航到右侧,并且该文本字段被禁用,则递归地再次调用右侧按钮。UITextField,用于细胞不可见已经userInteractionEnabled设置为无

看来,外面有什么可见的细胞的任何文本字段将被禁用。一旦用户到达桌子的边缘,我会进入无限循环,或者事情刚刚破裂。

这里是我的代码,我做我的启用检查,如果没有让我的递归调用部分。这真的不应该那么复杂。从逻辑上讲,我想要做的就是检测我们刚刚移动到的文本字段是否被禁用,如果是,则再次启动相同的按钮。没有什么花哨。

编辑有些游戏测试显示nextTextFieldSelection返回为null,虽然destinationIndexPath和newTag值是正确的。是否有可能请求indexPath不可见正在导致null返回?

 //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; 
     } 
    } 
+0

你每次调用'numerKeyboardView后更改标签? – Rakesh 2013-02-28 16:24:36

+0

是的,在我的逻辑改变文本字段,左边或右边的文本字段标签取决于用户如何浏览 – JMD 2013-02-28 16:27:10

+0

你所谈论的nextTextFieldSelection的标签正确设置? – Rakesh 2013-02-28 16:31:34

回答

2

cellForRowAtIndexPath对于不可见的单元格返回nil。这可能就是为什么你会陷入无限循环。

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

+0

繁荣,这正是它。我想我应该首先滚动我的视图,然后检查启用。 – JMD 2013-02-28 17:05:47

+0

如果我是你,我会将所有文本字段添加到数组中。那么即使它们不可见,你也可以回顾它们。 – pdrcabrod 2013-02-28 17:13:26

+0

这是我最初的计划,但随着表格单元的重复使用,一旦用户开始滚动,一切都会完全失序 – JMD 2013-02-28 17:17:11

相关问题