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

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

问题描述

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



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



在我的故事板中,我有2个自定义单元格:myCell数据承载单元,以及头部的headerCell。

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

 让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()开始/结束更新,它的功能正常,但标题背景变黑,并失去动画。



我拥有所有在头文件中声明的东西:func tableView(tableView:UITableView,viewForHeaderInSection section:Int) - > UIView?



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

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



我认为问题在于表单元格被重用的no索引路径。

解决方案

我在控制台输出中找到了答案。

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

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


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.

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"

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

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

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

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

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? 

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天全站免登陆