调整包含 UICollectionView 的 UITableViewCell 大小的示例

自动调整表视图大小包含 UI 的单元格

POC 的想法是验证是否可以不定义单元格高度并让自动调整大小时使用UITableView.automaticDimension

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableView.automaticDimension
}
实际 预期
模拟器屏幕截图 - iPhone SE(第 2 代) - 2022-03-24 在 22 25 20 模拟器屏幕截图 - iPhone SE(第 2 代) - 2022-03-24 在 22 25 55

File:

TableViewController: Contains the , implements DataSource methodsUITableView

CollectionViewCellTableViewCell: This is a that contains the it is register the and implements the UITableViewCellUICollectionViewUICollectionViewCellUICollectionViewDataSource

CollectionViewCell: The cell that is used by the UICollectionView

GitHub

点击跳转