iOS9 UIcollecionView crash 记录

2018-05-28  本文已影响11人  派大星的博客
    private func buildCollectionView() {
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 10
        layout.itemSize = CGSize(width: 130, height: 176 )
        layout.headerReferenceSize = CGSize(width: 130 , height: 176)
        let cvFrame = CGRect(x: 0, y: 0, width: ScreenWidth, height: 176)
        collectionView = UICollectionView(frame: cvFrame, collectionViewLayout: layout)
        collectionView.dataSource = self
        collectionView.delegate = self
        
        collectionView.register(ProductCell.self, forCellWithReuseIdentifier: "cell")
        collectionView.register(TitleHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "Header")

        collectionView.contentInset = UIEdgeInsets(top: 0, left: 23, bottom: 0, right: 23)
        collectionView.showsHorizontalScrollIndicator = false
        addSubview(collectionView)
    }

UICollectionView的崩溃经常在Debug环境也无法定位,因为Xcode不能提示你正确的崩溃位置在哪?(通常在外部或者main方法)

        layout.headerReferenceSize = CGSize(width: 130 , height: 176)

即,给定了HeaderView的size,但是并没有返回headerView。ios9中这是个必然会Crash的Bug,在ios10以后的版本已经优化了,不会出现Crash。

上一篇 下一篇

猜你喜欢

热点阅读