tableView节标题消失SWIFT

我有一个tableView设置,以便当一个单元格被触摸,它的高度展开,以显示更多的信息。 tableView有5个部分。

我有一个错误:当一个单元格展开时,该单元格下的所有headersCells不可见。 控制台输出如下内容:“[31233:564745]表格单元格重新使用没有索引path”

在我的故事板中,我有2个自定义单元格:数据承载单元格为“myCell”,标题为“headerCell”。

func tableView(tableView:UITableView,didSelectRowAtIndexPath indexPath:NSIndexPath){

let thisGoal : GoalModel = goalArray[indexPath.section][indexPath.row] if self.currentPath != nil && self.currentPath == indexPath { self.currentPath = nil } else { self.currentPath = indexPath } tableView.beginUpdates() tableView.endUpdates() } 

如果我在开始/结束更新之间inputtableView.reloadData(),它将正常运行,但标题背景变黑,并且会丢失animation。

我有所有的声明在头文件的东西:func tableView(tableView:UITableView,viewForHeaderInSection部分:INT) – > UIView?

我错过了什么? 我真的很喜欢tableView仍然有animation,并保持clearColor()的背景。

提前致谢。 我确实读了客观的答案,但无法让他们为我工作。 我非常感谢SWIFT的帮助。

我认为问题是表单元格被重用的no索引path。

我在控制台输出中find了答案。 在标题function中使用这个代码:

 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 

不要返回你的headerCell ,或者你的可重用的标识符。 返回reuseIdentifier.contentView 。 对我来说是: return headerCell!.contentView

由于我现在还没有50的声望,所以我不能评论以前的答案,所以我很抱歉把这个列为另一个答案。

返回ContentView将使该函数工作,但将删除对reuseIdentifier(headerCell)所做的所有格式化

 headerCell.backgroundColor = UIColor.cyanColor() 

这不会为您的headerCell提供青色

要解决这个问题,只需将“.contentView”添加到格式化行中即可

 headerCell.contentView.backgroundColor = UIColor.cyanColor() 

只是补充一点,当我能够清楚地看到它在那里的时候,为了我不能提到我的单元格的内容视图,我感到困惑不已。 我的自定义类(使用UITableViewCell而不是UITableViewHeaderFooterView)每次都会返回致命错误。 因此,确保在UITableViewHeaderFooterView类下设置任何自定义样式,如下所示:

 class CustomHeaderCell: UITableViewHeaderFooterView { 

您还需要像这样注册resuableIdentifer:

 tableView.registerNib(UINib(nibName: "HeaderCell", bundle: nil), forHeaderFooterViewReuseIdentifier: "CellHeader") 

那么这个坏男孩:

  func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let headerCell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("CellHeader") as! CustomHeaderCell! return headerCell!.contentView } 

当我将应用程序转换为IOS 10时,2个表格中的表格视图标题消失了 – 我在表格标题中find了Apple开发人员API文档中的原因。 当我添加以下内容时,丢失的标题重新出现!

 override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 44 // where 44 is the header cell view height in my storyboard }