JMD
JMD

Reputation: 1590

UITextField in cell that is not visible has userInteractionEnabled set to No

I am trying to skip over text fields that are disabled when a user navigates through my tableview. However, when they reach the bounds of the visible cells, everything gets out of whack because I am trying to detect if a text field is disabled, and if so, then recursively call my method again to navigate one more time. ie. if user presses a button to navigate to the right, and that text field is disabled, recursively call a right press again.

It seems, any text fields in cells outside what is visible are disabled. once the user reaches the edges of the table I go into infinite loops, or things just break.

here is my section of code where I make my enabled check and if not make my recursive call. This really shouldn't be that complicated. Logically all I want to do is detect if the text field we just moved to is disabled and if so, just initiate the same button press again. Nothing fancy.

edit with some playtesting it has become apparent that the nextTextFieldSelection is coming back as null, although the destinationIndexPath and newTag values are correct. Is it possible requesting an indexPath not visible is causing a null return?

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

Upvotes: 0

Views: 198

Answers (1)

pdrcabrod
pdrcabrod

Reputation: 1477

cellForRowAtIndexPath returns nil for not visible cells. Thats probably why you are getting into that infinite loop.

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

Upvotes: 2

Related Questions