【问题标题】:Wrong height info from tableView.contentSize.height来自 tableView.contentSize.height 的错误高度信息
【发布时间】:2021-12-17 21:29:55
【问题描述】:

我有一个视图控制器,并且该视图控制器上的 tableview 单元格中有一个容器视图。

容器视图中还有另一个tableview。

所以我将数据加载到容器视图中的 tableview 中,并使用 nsnotificationcenter 将 self.tableView.contentSize.height 信息发送到父视图控制器。

我用

 tableView.estimatedRowHeight = UITableView.automaticDimension
 tableView.rowHeight = UITableView.automaticDimension

并根据内容动态改变行高

但是,这个高度信息tableView.contentSize.height 总是错误的(低于预期)。我怎样才能得到正确的信息?

【问题讨论】:

  • 也许使用 DispatchQueue.main.async。或者 func tableView(_ tableView: UITableView, heightForRowAt _indexPath: IndexPath) 进行精确的高度计算,然后返回表格高度的精确值。

标签: ios swift xcode uitableview


【解决方案1】:

不确定它是否有效,但您可以尝试根据容器视图的尺寸为外部 tableview 设置systemLayoutSizeFitting 函数。请记住将内部表的前导、尾随、顶部和底部约束到容器视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 2014-06-02
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    相关资源
    最近更新 更多