ios - 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
}
}
解决方案
我能够用不同的方法解决问题。我为我的 collectionviewcell 创建了一个 xib 文件,并在那里添加了我的子视图。现在一切正常,但为我最初的问题找到解决方案仍然很棒。
推荐阅读
- ios - 如何在circleci中添加插件fastlane-plugin-appicon?
- django - Django,DRF(&React)外键,如何显示名称值而不是外键id
- mysql - MySQL 搜索/替换为 '\/'
- php - 获取最新版本的 mPDF (7.1) 以使用 phpExcel?
- python - 如何对 dask.dataframe 中的一行进行子集化?
- python-3.x - 是否可以运行一个 for 循环来绘制图形并在顶部生成一个目录,其中显示每个顶部的位置?
- hyperledger-fabric - 使用自定义超级账本结构网络“fabcar”调整超级账本卡尺
- c# - 获取参数的全名(命名空间、类、方法和名称)c#
- c++ - 如何在保持显示位数的同时向左移动小数点?
- python - Python 使用 __init__.py 从其他文件夹(在同一个项目中)导入文件?