我有以下内容UICollectionViewCompositionalLayout
:
public lazy var layout: UICollectionViewLayout = {
let layout = UICollectionViewCompositionalLayout {
(sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(115))
var count: Int = 2
if self.view.traitCollection.horizontalSizeClass != .compact {
if self.view.frame.size.width > 900 {
count = 5
} else {
count = 3
}
}
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: count)
let spacing = CGFloat(10)
group.interItemSpacing = .fixed(spacing)
let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = spacing
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
return section
}
return layout
}()
当我在 iOS 上运行它时它工作正常,但是当我使用 Catalyst 在 Mac 上运行它时,它会抛出以下错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot solve for a non-group item.'
有想法该怎么解决这个吗?