swift - UITableViewCell 中的 UICollectionView — 动态高度计算不正确
问题描述
我在表格视图单元格中有一个动态高度集合视图。我在本主题中使用了@Igor 方法。 UITableViewCell 内的 UICollectionView - 动态高度?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DraftCustomerTableViewCell", for: indexPath) as! DraftCustomerTableViewCell
cell.data = notificationDraftListViewData[indexPath.section]
cell.frame = tableView.bounds
cell.collectionView.reloadData()
cell.collectionViewHeightConstraint.constant = cell.collectionView.collectionViewLayout.collectionViewContentSize.height
cell.layoutIfNeeded()
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
dict[indexPath] = cell.frame.size.height
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return dict[indexPath] ?? CGFloat(450)
}
问题是当我第一次展开 tableview 部分时,单元格的高度计算不正确。第一次展开后,collectionView 的高度可以正确计算。我尝试在不点击按钮的情况下让我的 data[0].isExpand 为真,并发现表格视图的单元格高度是正确的。请看演示。有什么方法可以避免这个问题吗?谢谢。
解决方案
推荐阅读
- node-red - Watson Assistant NodeRed 节点不接受新的 IAM 安全凭证
- angular - 角度材料选项卡高度
- javascript - Angular-tree-component 不显示任何节点
- ios - 使用 OHHTTPStubs 模拟时未达到 Alamofire 响应块
- python - Python 3: vehicle inventory using class
- javascript - 将项目移动到不同位置后的淘汰排序更新功能
- android - 在 Android 的 volley 中使用 Get 方法向 Spring 框架(MVC)发送请求
- go - 如何找到 go 包的版本
- c - 这个 char* 任务发生了什么?(混合类型的逗号运算符)
- java - 使用 Apache FOP 生成的 PDF 为空