CollectionView里面的CollectionView | CollectionViewCell自动布局错误

时间:2018-08-03 12:40:27

标签: ios swift uicollectionview uicollectionviewcell

我有一个collectionview(A),可将我用作“卡片视图”以快速浏览。在最后一张卡/单元格中,我有另一个collectionview(B)显示更多单元格。 到目前为止,一切都很好!添加标签按钮或其他视图后,会出现以下错误:

  

线程1:信号SIGABRT   -[NSISEngine nsli_layoutEngine]:无法识别的选择器已发送到实例0x10737e6b0   ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[NSISEngine   nsli_layoutEngine]:无法识别的选择器已发送到实例   0x10737e6b0'

collectionview(A)的单元格确认到Collectionview(B)的CollectionviewDataSource / Delegate

这是我的collectionview(B)的单元格类:

class UpcommingTimerCell: UICollectionViewCell {

override init(frame: CGRect) {
    super.init(frame: frame)

    setupTimerIdLabel()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}




//MARK: - setup subviews

func setupTimerIdLabel(){
    self.addSubview(timerIdLabel)

    if #available(iOS 11.0, *) {
        NSLayoutConstraint.activate([
            timerIdLabel.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor),
            timerIdLabel.leadingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.leadingAnchor),
            timerIdLabel.trailingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.trailingAnchor),
            timerIdLabel.heightAnchor.constraint(equalToConstant: 20)
            ])
    } else {
        // Fallback on earlier versions
    }
}

1 个答案:

答案 0 :(得分:0)

我能够用另一种方法解决问题。 我为collectionviewcell创建了一个xib文件,并在其中添加了子视图。现在一切正常,但是为我的最初问题找到解决方案仍然很棒。

相关问题