UICollectionView and Supplementary View (header)

前端 未结 10 1130
南旧
南旧 2021-02-04 05:17

Trying to add a a Supplementary view into my UICollectionView as a header. I\'m having issues getting it to work.

I use a custom UICollectionViewFlowL

10条回答
  •  情深已故
    2021-02-04 05:41

    This answer is similar to the others where you create a method that checks for the data source, but it's a bit simpler. It seems the issue is related to the collection view's layout sticking around after the collection has been released. So I zeroed out the layout's properties as below and the error disappeared.

    deinit {
        let layout = self.collectionView.collectionViewLayout as! UICollectionViewFlowLayout
        layout.estimatedItemSize = CGSizeZero
        layout.sectionInset = UIEdgeInsetsZero
        layout.headerReferenceSize = CGSizeZero
    }
    

提交回复
热议问题