What is the meaning of the “no index path for table cell being reused” message in iOS 6/7?

前端 未结 14 2230
一整个雨季
一整个雨季 2020-11-27 15:12

Since starting to compile my app with iOS 6 (and since also iOS 7) I\'ve started seeing this message. I know that the way that UITableViews go about managing cells is diffe

相关标签:
14条回答
  • 2020-11-27 15:52

    Addition to the accepted answer (mluisbrown), I needed to add an autoresizingMask to the header cell, since mine contained a multi-line label, i.e.

    UIView *view = [[UIView alloc] initWithFrame:[cell frame]];
    cell.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [view addSubview:cell];
    return view;
    
    0 讨论(0)
  • 2020-11-27 15:52

    Well, I just used the better part of a day trying to figure this out, so hopefully this alternative explanation saves somebody else some time.

    I had a tableview which was giving this message sometimes, when loading. It turned out to be caused by KVO notifications for Core Data objects firing while the view was loading. (On observing a change, my controller tried called reloadData on the tableview in question. Fixed by not observing the objects until the view had finished loading (previously I started observing the object once it was assigned via the accessor)

    TLDR: Check to see if you might be trying to reload your data from something other than the main thread.

    0 讨论(0)
  • 2020-11-27 15:55

    I had the same problem with the error message appearing. As far as I can see it is caused by reloading the table view from a function called by the the textfield as part of its delegate protocol. Ie textFieldDidEndEditing -> [controller.tableview reload...]

    0 讨论(0)
  • 2020-11-27 15:55

    Yet another condition...

    This happened when, not wanting a header, I returned nil.

    Fix:

    func tableView(tableView: UITableView,
                   titleForHeaderInSection section: Int) -> String? {
        return ""
    }
    
    0 讨论(0)
  • 2020-11-27 15:57

    I had the same problem and it took me few hours to hunt down the issue. Turns out I was calling [textField becomeFirstResponder] while setting up cells (here the textField was part of a custom tableviewcell); [textField becomeFirstResponder]in turns posts keyboardWillShow notification which in turn caused the tableview to prematurely load itself thus causing the infamous "no index path for table cell being reused” message. Once I removed that call, problem disappeared.

    0 讨论(0)
  • 2020-11-27 16:00

    This is an internal UIKit bug - as mentioned in Apple's own dev forums. It's supposedly fixed in newer versions of xcode, although I wasn't able to find info regarding which version fixes this.

    0 讨论(0)
提交回复
热议问题