No index path for table cell being reused

前端 未结 13 1498
执念已碎
执念已碎 2021-02-04 05:18

This started to happen out of the blue. Any ideas: Code:

CUSTOMCLASSNAME (I have replaced the actual class name as it contains the name of the client.)

Initialis

相关标签:
13条回答
  • 2021-02-04 05:52

    I worked this out after a few days. In my custom cell I had a textView, when I was adding it to the contentView I was doing this:

    [self.cellTextView setClearsOnInsertion:YES];
    

    This was the cause of the issue; incase anyone else has a similar problem.

    Happy coding :-)

    0 讨论(0)
  • 2021-02-04 05:53

    In my case, this error was presented only on iPhone (not iPad) because I had placed [self.tableView beginUpdates]; and later [self.tableView endUpdates]; inside [UIView transitionWithView:duration:options:animations:compeletion];. To fix, I just removed begin/end updates, as I preferred a fading animation instead of fading plus animating cell height changes.

    0 讨论(0)
  • 2021-02-04 05:54

    I had the same issue. This message appears when I scroll and cells are reused.

    A lot answers talked about viewForHeaderInSection but I didn't use them. In case someone has the similar problem, I hereby show my solution.

    I added observer to the textfields inside each cell. I wonder whether this is the observer that caused this issue as I didn't remove the observers when a cell is recycled.

    So I removed the observer when a cell is deinited.

    It seems the problem is solved. I cannot guarantee.

    0 讨论(0)
  • 2021-02-04 05:58

    I found this warning during my viewForHeaderInSection implementation.

    This is my solution in Swift 2.x:

    let headerView = self.tableView.dequeueReusableCellWithIdentifier("MyCell") as! MyCell
    let containerView = UIView(frame:headerView.frame)
    headerView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
    headerView.myLabel.text = "section title 1"
    containerView.addSubview(headerView)
    return containerView
    

    This is the Swift 3 version:

    let headerView = self.tableView.dequeueReusableCell(withIdentifier: "MyCell") as! MyCell
    let containerView = UIView(frame:headerView.frame)
    headerView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    headerView.myLabel.text = "section title 1"
    containerView.addSubview(headerView)
    return containerView
    
    0 讨论(0)
  • 2021-02-04 06:01

    I received the same error, but for a different reason.

    I had a custom UITableViewCell that set one of the UITextField's to becomeFirstResponder. The error occurred when more than one instance of this custom cell was being returned.

    I simply set only the first instance of the custom cell to becomeFirstResponder and it resolved the issue.

    0 讨论(0)
  • 2021-02-04 06:02

    I have just tracked down a cause of this error message.

    A UITableViewCell was being used as a normal view. Therefore its' indexPath was not set. In our case one was being returned by viewForHeaderInSection:

    Hope this helps.

    Chris

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