tableView section headers disappear SWIFT

前端 未结 6 1400
慢半拍i
慢半拍i 2020-12-13 18:01

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 e

6条回答
  •  萌比男神i
    2020-12-13 18:20

    Just to add, I was baffled for WAY longer than I should have been as to why I couldn't refer to the contentView of my cell, when I could quite clearly see it was there. My custom class (using UITableViewCell rather than UITableViewHeaderFooterView) would return a fatal error each time. Therefore make sure any custom styling is setup under UITableViewHeaderFooterView class like:

    class CustomHeaderCell: UITableViewHeaderFooterView {
    

    You will also need to register the resuableIdentifer like this:

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

    Then this bad boy:

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

提交回复
热议问题