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

原因

  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()
    }

 

你可能感兴趣的:(#,swift)