Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

ios - tableView section headers disappear SWIFT

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...