【问题标题】:UICollectionview in UIStackView in UITableViewCellUITableViewCell 中的 UIStackView 中的 UICollectionview
【发布时间】:2018-08-10 18:54:05
【问题描述】:

我有一个tableview,希望根据数据动态地向它添加视图。对于其他所有视图,这很容易。像魅力一样工作,但collectionview,我什至看不到stackview 上的视图。

UICollectionView'scellForItem 委托未被调用,numberOfItems 委托被调用但cellForItem 未被调用。

不确定我是否遗漏了什么。

  func testView() -> UIView {
    let containerView = UIView(frame: .zero)
    containerView.backgroundColor = .red

    let layout = KTCenterFlowLayout()
    layout.minimumInteritemSpacing = 10.0
    layout.minimumLineSpacing = 10.0
    layout.estimatedItemSize = CGSize(width: 80, height: 100)
    layout.sectionInset = UIEdgeInsetsMake(20, 30, 20, 30)
    let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout).then {
        $0.dataSource = self
        $0.isScrollEnabled = false
        $0.setCollectionViewLayout(layout, animated: false)
        $0.register(NPSCollectionViewCell.self, forCellWithReuseIdentifier: "npsCell")
        $0.contentSize = CGSize(width: view.frame.size.width-100, height: 500.0)
        containerView.addSubview($0)
    }
    collectionView.snp.makeConstraints { (make) in
        make.edges.equalToSuperview()
        make.height.equalTo(500).priority(500)
    }
    return containerView
}

我在CellForRowAtIndexPath 中添加上面的视图

     cell?.stackView.addArrangedSubview(testView())

任何指针?

编辑:这是截图 我只看到一个空白

这是我的StackTableViewCell

       lazy var stackView : UIStackView! = {
    let stack = UIStackView()
    stack.axis = .vertical
    stack.distribution = .fillProportionally
    stack.alignment = .center
    stack.spacing = 10.0
    stack.translatesAutoresizingMaskIntoConstraints = false
    stack.setContentCompressionResistancePriority(UILayoutPriority.required, for: .vertical)
    return stack
}()

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    contentView.addSubview(stackView)
    stackView.snp.makeConstraints { (make) in
        make.top.equalToSuperview().offset(10)
        make.left.equalToSuperview().offset(20)
        make.right.equalToSuperview().offset(-20)
        make.bottom.equalToSuperview().offset(-10)
    }

【问题讨论】:

    标签: ios swift uitableview uicollectionview uistackview


    【解决方案1】:

    我遇到了一个单元格没有显示的问题,我只是使用 collectionView 的属性手动给它一个大小尝试这种方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2015-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多