Question

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";
}
Was it helpful?

Solution 5

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 :-)

OTHER TIPS

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

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

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.

If you are using the cell for the header view section header, you have to put it into the container and then return the container view to prevent "no index path for table cell being reused". The sample code as below.

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    CustomerCellHeader *headerViewCell = [tableView dequeueReusableCellWithIdentifier:kCustomerCellHeaderIdentifier];
    headerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [headerView addSubview:headerViewCell];
    return headerView;
}

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.

EVEN BETTER:

This is a problem that you won't run into if you (as I've discovered you really should) use child managed object contexts and only merge changes back into your main MOC on the main thread at sensible times.

I had issues with returning a UITableViewCell in tableView:viewForHeaderInSection, but returning [cell contentView] was causing any buttons within the cell to crash, and setting a view wrapper around the cell seemed wasteful. Instead, I changed my UITableViewCell class to a UITableViewHeaderFooterView and it worked like a charm!

If you get this issue:

Setting the background color on UITableViewHeaderFooterView has been deprecated. Please use contentView.backgroundColor instead.

Just remember to change the background color on your nib to default.

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.

It helped me in swift 2.1

  func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView {
            let headerCell:SBCollapsableTableViewHeader = self.friendsInfoTableView.dequeueReusableCellWithIdentifier("HeaderCell") as! SBCollapsableTableViewHeader
            let containerView = UIView(frame:headerCell.frame)
            headerCell.delegate = self
            headerCell.titleLabel.font = UIFont.boldSystemFontOfSize(15)
            headerCell.titleLabel.text = "\(self.ObjectArray[section].sectioName)"
            headerCell.collapsedIndicatorLabel.text = collapsed ? "+" : "-"
            headerCell.tag = section
            headerCell.backgroundColor =  UIColor(red:72/255,green:141/255,blue:200/255,alpha:0.9)
            containerView.addSubview(headerCell)
            return containerView
    }

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.

In my case (pretty stupid one), I used the if let syntax inside cellForRowAt like that:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if let cell = tableView.dequeueReusableCell(withIdentifier: "carCell", for:
    indexPath) as? carTableViewCell {
        // Did some stuff here
        return CarTableViewCell()
    else {
        return CarTableViewCell()    
    }
}

As you may see, I returned i generic carTableViewCell(), and that's what gave me that despicable error... I hope it will ever help someone haha (:

Happy Coding!

can you try the following (provided you do not have any specific configuration for a cell at that indexpath) :-

CustomClassName *cell=[tableView dequeueReusableCellWithIdentifier:[self reuseIdentifier]];
if(cell==nil)
{
cell=[[CustomClassName alloc] initWithStyle:whatever_style reuseIdentifer:[self reuseIdentifier]];
}

Please also post what error you are getting if the above does not work.

Also have a look at the following link:-

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top