首页 > 解决方案 > CollectionView 里面的 CollectionView | CollectionViewCell 自动布局错误

问题描述

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

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

用于collectionview(A) 的单元格确认CollectionviewDataSource/Delegate 用于collectionview(B)

这是我的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
    }
}

标签: iosswiftuicollectionviewuicollectionviewcell

解决方案


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


推荐阅读