我将水平UICollectionView固定到的所有边缘UITableViewCell。集合视图中的项目是动态调整大小的,我想使表视图的高度等于最高的集合视图单元格的高度。
视图的结构如下:
UITableView
UITableViewCell
UICollectionView
UICollectionViewCell
UICollectionViewCell
UICollectionViewCell
class TableViewCell: UITableViewCell {
private lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: self.frame, collectionViewLayout: layout)
return collectionView
}()
var layout: UICollectionViewFlowLayout = {
let layout = UICollectionViewFlowLayout()
layout.estimatedItemSize = CGSize(width: 350, height: 20)
layout.scrollDirection = .horizontal
return layout
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
let nib = UINib(nibName: String(describing: CollectionViewCell.self), bundle: nil)
collectionView.register(nib, forCellWithReuseIdentifier: CollectionViewCellModel.identifier)
addSubview(collectionView)
// (using SnapKit)
collectionView.snp.makeConstraints …Run Code Online (Sandbox Code Playgroud) 我有一个UIStackView可以显示标签,图像,表视图或根据用户选择的任何内容.这是我当前动态视图的层次结构:
当我UIStackView_Child.addArrangedSubview(...)使用标签或图像调用时,它可以完美地工作,但addArrangedSubview(tableView)不会显示表格.我tableView.scrollEnabled = false根据单元格的数量将框架设置为固定高度并定义了表格cellHeight.
任何帮助将不胜感激,谢谢!