表格单元没有被重用的索引path

这开始发生了蓝色。 任何想法:代码:

CUSTOMCLASSNAME(我已经replace了实际的类名,因为它包含了客户端的名字)

初始化我的tableView:

[self.tableView registerClass:[CUSTOMCLASSNAME class] forCellReuseIdentifier:[self reuseIdentifier]]; 

在行的单元格中:

嗨,标题正在打印在控制台。 这是我的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"; } 

tableView:viewForHeaderInSection:返回[cell contentView]而不是cell tableView:viewForHeaderInSection:

编辑:这不知何故导致在UIbutton上的长按手势崩溃。 为了解决这个问题,我放弃了用单个项目的另一个部分作为假部分标题。

我在viewForHeaderInSection实现中发现了这个警告。

这是我在Swift 2.x中的解决scheme:

 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 

这是Swift 3版本:

 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 

我刚刚查明了这个错误信息的原因。

UITableViewCell被用作普通视图。 因此它的indexPath没有设置。 在我们的例子中,一个被viewForHeaderInSection返回:

希望这可以帮助。

克里斯

在我的情况下,这个错误只在iPhone上(而不是iPad),因为我已经放置[self.tableView beginUpdates]; 后来[self.tableView endUpdates]; 里面[UIView transitionWithView:duration:options:animations:compeletion]; 。 为了解决这个问题,我只是删除了开始/结束的更新,因为我更喜欢淡入淡出的animation,而不是淡入淡出,加上animation细胞高度的变化。

几天之后我就解决了这个问题。 在我的自定义单元格中,我有一个textView,当我将它添加到contentView我这样做:

 [self.cellTextView setClearsOnInsertion:YES]; 

这是问题的原因; 任何人都有类似的问题。

快乐编码:-)

如果使用单元格作为标题视图节标题,则必须将其放入容器中,然后返回容器视图以防止“表格单元格没有被重用的索引path”。 示例代码如下。

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

那么,我只是用了一天中最好的一部分来解决这个问题,所以希望这个替代解释可以节省一些人的时间。

我有一个桌面视图,有时这个消息,加载时。 事实certificate,这是由加载视图时触发核心数据对象的KVO通知造成的。 (在观察一个变化的时候,我的控制器在桌面视图上试图调用reloadData,通过在视图加载完成之前不观察对象来进行修复(以前我通过访问器分配了对象之后开始观察对象)

TLDR:检查你是否试图从主线程以外的地方重新加载你的数据。

甚至更好:

如果你(正如我发现你真的应该)使用子pipe理的对象上下文,并且只在合理的时间将更改合并回主线程中的主MOC,那么这是一个你不会碰到的问题。

我在tableView:viewForHeaderInSection返回一个UITableViewCell遇到了问题,但是返回[cell contentView]导致单元格内的任何button崩溃,并且在单元格周围设置视图封装器看起来很浪费。 相反,我改变了我的UITableViewCell类到一个UITableViewHeaderFooterView ,它的工作就像一个魅力!

如果你遇到这个问题:

在UITableViewHeaderFooterView上设置背景颜色已被弃用。 请改用contentView.backgroundColor。

只记得把你的笔尖的背景颜色改为默认的。

我遇到过同样的问题。 当我滚动和重复使用单元格时出现此消息。

很多回答谈到viewForHeaderInSection,但我没有使用它们。 如果有人有类似的问题,我特此表明我的解决scheme。

我将观察者添加到每个单元格内的文本字段。 我想知道这是否是导致这个问题的观察者,因为当一个单元被回收时,我没有移除观察者。

所以,当一个细胞被囚禁的时候,我把这个观察者移开了。

看来问题解决了。 我不能保证。

它帮助我迅速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 } 

我收到了同样的错误,但出于不同的原因。

我有一个自定义UITableViewCell设置其中一个UITextField的成为FirstResponder。 当这个自定义单元格的多个实例被返回时发生错误。

我只是简单地设置自定义单元格的第一个实例成为FirstResponder,并解决了问题。

在我的情况下(非常愚蠢的),我使用cellForRowAt语句里面的cellForRowAt像这样:

 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() } } 

正如你所看到的,我回到了我的通用carTableViewCell(),这就是给了我那个卑鄙的错误…我希望它会永远帮助别人哈哈(:

快乐编码!

你可以尝试下面的内容(假设你没有任何特定的configuration为该索引path的单元格): –

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

如果上述不起作用,请也发布你得到的错误。

也看看下面的链接:

在iOS 6/7中,“表格单元没有被重用的索引path”消息的含义是什么?