No index path for table cell being reused
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.
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
Return [cell contentView]
instead of cell
from tableView:viewForHeaderInSection:
EDIT: This somehow led to crashes on long-press gestures on UI Buttons. To fix that, I gave up and used another section with a single item as a fake section header.
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