Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UITableView中获取动态大小的节标题的高度?_Ios_Swift_Uitableview - Fatal编程技术网

Ios 如何在UITableView中获取动态大小的节标题的高度?

Ios 如何在UITableView中获取动态大小的节标题的高度?,ios,swift,uitableview,Ios,Swift,Uitableview,我有一个UITableView,它使用自定义UIView作为节头视图。代码如下: func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return UITableViewAutomaticDimension } func tableView(_ tableView: UITableView, viewForHeaderInSection section

我有一个
UITableView
,它使用自定义
UIView
作为节头视图。代码如下:

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  return UITableViewAutomaticDimension
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "ECStartTableHeaderView") as! ECStartTableHeaderView
  return headerView
}

我有头上高度的
UITableViewAutomaticDimension
。我需要找出代码中的高度。如何获得此页眉高度?

我认为您必须确保首先完成页眉布局,以便获得实际高度

func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    let height = view.frame.height
}

您可以取出标题视图的高度,如下所示

if let headerView = tableView.tableHeaderView {
   height = headerView.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height
}

可能是
tableView.headerView(第0节)?高度
?只是不确定你想在哪里得到高度