0
点赞
收藏
分享

微信扫一扫

UICollectionView must be initialized with a non-nil layout parameter【已经解决】

夹胡碰 2023-03-10 阅读 31


原因

collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height))

UICollectionView 中没有使用如双参数的初始化方法

解法

collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height),collectionViewLayout: flowLayout)

补充是在init代码中的所有源码:
 

override init(frame: CGRect) {
flowLayout = UICollectionViewFlowLayout()
flowLayout.headerReferenceSize = .zero
flowLayout.footerReferenceSize = .zero
flowLayout.minimumLineSpacing = 0
flowLayout.minimumInteritemSpacing = 0
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
flowLayout.scrollDirection = .horizontal

collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height),collectionViewLayout: flowLayout)
pageControl = UIPageControl()
super.init(frame:frame)
self.setupViews()
}

 

举报

相关推荐

0 条评论