單元格中不可見的 UITextField 已將 userInteractionEnabled 設置為 No (UITextField in cell that is not visible has userInteractionEnabled set to No)


問題描述

單元格中不可見的 UITextField 已將 userInteractionEnabled 設置為 No (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;
        }
    }

‑‑‑‑‑

參考解法

方法 1:

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

(by JMDpdrcabrod)

參考文件

  1. UITextField in cell that is not visible has userInteractionEnabled set to No (CC BY‑SA 3.0/4.0)

#cocoa #objective-c #iphone #iOS #ipad






相關問題

為什麼 NSWindow 或 NSView 實例處理它自己的鍵事件,而不是它的委託? (Why does an NSWindow or NSView instance handle its own key events, and not its delegate?)

通過 IKImage 視圖預覽圖像 (Previewg images via IKImage View)

Gaya Jendela Kustom di Kakao (Custom Window Style in Cocoa)

Apakah NSURLConnections termasuk dalam model atau pengontrol saya? (Do NSURLConnections belong in my model or controller?)

Эквівалент ключа NMenuItem не працуе, калі меню схавана (NSMenuItem Key Equivalent not working when menu is hidden)

透明窗口中的圓形 NSView (Rounded NSView in a Transparent Window)

單元格中不可見的 UITextField 已將 userInteractionEnabled 設置為 No (UITextField in cell that is not visible has userInteractionEnabled set to No)

如何為自定義 NSImageRep 子類實現 -draw (How to implement -draw for custom NSImageRep subclass)

從 Objective-C 中的核心數據元素獲取和設置值? (Getting and Setting values from Core Data elements in Objective-C?)

來自 URL 編碼問題的 NSArray (NSArray from URL encoding problem)

停靠欄下的窗口化opengl遊戲中的雙光標 (Double cursor in windowed opengl game under dock)

在特定的 NSTableview 單元格中對角線繪製線條 (Draw Lines Diagonally in a particular NSTableview cell)







留言討論