tableView 部分标题消失 SWIFT [英] tableView section headers disappear SWIFT

查看:17
本文介绍了tableView 部分标题消失 SWIFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个 tableView,以便在触摸单元格时,它会扩展高度以显示更多信息.tableView 有 5 个部分.

I have a tableView set up so that when a cell is touched, it expands in height to reveal more information. The tableView has 5 sections.

我有一个错误:当单元格展开时,该单元格下方的所有 headersCells 都将不可见.控制台输出如下:[31233:564745] no index path for table cell being reused"

I have a bug: when a cell expands, all headersCells below that cell go invisible. The console outputs the following: "[31233:564745] no index path for table cell being reused"

在我的故事板中,我有 2 个自定义单元格:"myCell" 用于数据承载单元格,"headerCell" 用于标题.

In my storyboard I have 2 custom cells : "myCell" for the data bearing cells, and "headerCell" for the headers.

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

如果我在开始/结束更新之间输入 tableView.reloadData(),它会正常运行,尽管标题背景变黑并失去动画效果.

If I enter tableView.reloadData() in between the begin/end updates, it functions properly, although the header background turns black, and loses animation.

我有所有声明的标题的东西: func tableView(tableView: UITableView, viewForHeaderInSection section: Int) ->界面视图?

I have all of the stuff for headers declared in: func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?

我错过了什么?我真的很希望 tableView 仍然有动画,并保持背景 clearColor().

what am I missing? I'd really like the tableView to still have animations, and keep the background clearColor().

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

Thanks in advance. I did read through the objective C answers, but couldn't get them to work for me. I'd really appreciate some SWIFT help.

我认为问题在于重复使用表格单元格的无索引路径.

I think the problem is the no index path for table cell being reused.

推荐答案

我在控制台输出中找到了答案.在标头函数中使用此代码:

I found an answer in the console output. Use this code in the header function:

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

不要返回您的 headerCell 或可重复使用的标识符.返回 reuseIdentifier.contentView.对我来说是:return headerCell!.contentView.

Do not return your headerCell, or your reusable identifier. Return the reuseIdentifier.contentView. For me it's: return headerCell!.contentView.

这篇关于tableView 部分标题消失 SWIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆