子类UICollectionView并尝试在Storyboard VC中设置。
class CategoryCollectionView: UICollectionView, UICollectionViewDelegate, ReusableView, NibLoadableView {
/// Local
var categoryDataSource: CategoryDataSource!
typealias CategoryDataSource = UICollectionViewDiffableDataSource<Section, CommunityType>
typealias CategorySnapshot = NSDiffableDataSourceSnapshot<Section, CommunityType>
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: collectionViewLayout)
configure()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
fileprivate func configure() {
self.register(CardTypeCell.self)
self.collectionViewLayout = createLayout()
self.delegate = self
}
private func createLayout() -> UICollectionViewLayout {
let padding: CGFloat = 5
let flowLayout = UICollectionViewFlowLayout()
flowLayout.sectionInset = UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding)
flowLayout.itemSize = CGSize(width: 152, height: 70)
flowLayout.scrollDirection = .horizontal
flowLayout.sectionHeadersPinToVisibleBounds = true
return flowLayout
}
}init方法中的一个错误:'self‘在“super.init”调用之前用于属性访问'collectionViewLayout’
发布于 2020-12-01 17:46:30
不是100%肯定,因为我们遗漏了很多您的代码(Section、CommunityType等),但是.
这一行:
super.init(frame: frame, collectionViewLayout: collectionViewLayout)应:
super.init(frame: frame, collectionViewLayout: layout)https://stackoverflow.com/questions/65086515
复制相似问题