0

I am using the code below to set the uitableview viewForHeaderInSection and then I am trying to update just one textfield in the section header but my reference is nil.

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: "ReusableHeader")

        header.timeField.text = String(describing: secondsToHoursMinutesSeconds(seconds: counter))
        return header
    }

My reference code where header comes back as nil:

let header = self.tableView.headerView(forSection: 0)
        header?.setNeedsLayout()
user1079052
  • 3,803
  • 4
  • 30
  • 55
  • 1
    Why are you attempting to dequeue a cell for a section header? Cells are for rows, not header views. – rmaddy Oct 03 '17 at 15:21
  • I am using a custom cell for my headerview. Is there another way I should be doing it? – user1079052 Oct 03 '17 at 15:38
  • Look at the documentation for `UITableViewHeaderFooterView`. – rmaddy Oct 03 '17 at 15:39
  • I have read it before, what am I missing? – user1079052 Oct 03 '17 at 15:50
  • 1
    After reading the documentation you then need to actually use `UITableViewHeaderFooterView` and `dequeueReusableHeaderFooterView` instead of using cells for your section header. – rmaddy Oct 03 '17 at 15:52
  • See https://stackoverflow.com/questions/40165210/on-swipe-to-delete-the-header-and-footer-section-of-the-tableview-swipe-too – rmaddy Oct 03 '17 at 15:54

1 Answers1

0

Ok , i'am researching about this thing. func self.tableView.headerView(forSection: ) return only UITableViewHeaderFooterView object. If you want use this func , you need use tableView.dequeueReusableHeaderFooterView(withIdentifier: "ReusableHeader")

 public override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
    let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: "ReusableHeader")
    return view
}