【发布时间】: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