No index path for table cell being reused
Solution 1
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 :-)
Solution 2
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.
Solution 3
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
Solution 4
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
Solution 5
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.
CW0007007
iOS Contractor Developer - Available for short and Long term contract roles. Most notable projects: https://github.com/orgs/Donky-Network/dashboard
Updated on June 14, 2022Comments
-
CW0007007 about 2 years
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.)
Initialising my tableView:
[self.tableView registerClass:[CUSTOMCLASSNAME class] forCellReuseIdentifier:[self reuseIdentifier]];
In cell for row:
Hi, the title is being printed in the console. This is my cellForRow:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { AVTCheckListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self reuseIdentifier] forIndexPath:indexPath]; [self configureCell:cell atIndexPath:indexPath]; return cell; } - (void)configureCell:(AVTCheckListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { ChecklistGroup *group = [self.checklistFetchedResultsController.fetchedObjects objectAtIndex:indexPath.section]; ChecklistItem *item = [self getChecklistItemForIndexPath:indexPath]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [[cell cellTextView] setAttributedText:[[item checked] boolValue] ? [[NSAttributedString alloc] initWithString:[item name] attributes:@{ NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle) } ] : [[NSAttributedString alloc] initWithString:[item name]]]; [[cell cellTextView] setUserInteractionEnabled:[[group isUserDefined] boolValue]]; [[cell cellTextView] setTag:indexPath.row]; [[cell cellTextView] setDelegate:self]; [[cell tickImage] setHidden:![[item checked] boolValue]]; } //Method that returns re-use: - (NSString *) reuseIdentifier { return @"CheckListTableView"; }