相关疑难解决方法(0)

动态高度UITableViewCell内的动态高度UICollectionView

我将水平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)

uitableview ios uicollectionview swift

21
推荐指数
2
解决办法
925
查看次数

UITableView中没有显示UITableView

我有一个UIStackView可以显示标签,图像,表视图或根据用户选择的任何内容.这是我当前动态视图的层次结构:

  • UIStackView_Parent
    • UILabel - 一些文字,固定视图
    • UIStackView_Child - 这是可以显示多个内容或什么都不显示的容器
    • UIView - 另一个固定视图

当我UIStackView_Child.addArrangedSubview(...)使用标签或图像调用时,它可以完美地工作,但addArrangedSubview(tableView)不会显示表格.我tableView.scrollEnabled = false根据单元格的数量将框架设置为固定高度并定义了表格cellHeight.

任何帮助将不胜感激,谢谢!

ios swift uistackview

4
推荐指数
2
解决办法
6638
查看次数

标签 统计

ios ×2

swift ×2

uicollectionview ×1

uistackview ×1

uitableview ×1