0

我正在使用下面的代码来设置 uitableview viewForHeaderInSection,然后我试图只更新节标题中的一个文本字段,但我的参考是零。

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

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

我的标头返回为零的参考代码:

let header = self.tableView.headerView(forSection: 0)
        header?.setNeedsLayout()
4

1 回答 1

0

好的,我正在研究这件事。func self.tableView.headerView(forSection: )只返回UITableViewHeaderFooterView对象。如果你想使用这个函数,你需要使用tableView.dequeueReusableHeaderFooterView(withIdentifier: "ReusableHeader")

 public override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
    let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: "ReusableHeader")
    return view
}
于 2017-10-03T19:46:13.127 回答