UICollectionView and Supplementary View (header)

前端 未结 10 1127
南旧
南旧 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:35

    I faced with the similar problem, but my app crashed after I programmatically pop my UICollectionViewController. In some reason (I think it's just a bug in SDK) self.collectionView was alive after its' controller destroy, thus causing this failure:

    *** Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /SourceCache/UIKit/UIKit-2935.137/UICollectionView.m:1305
    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set'
    

    The solution is just override -dealloc in UICollectionViewController and release self.collectionView manually. ARC code:

    - (void)dealloc {
    
        self.collectionView = nil;
    }
    

    Hope this will save time for somebody.

提交回复
热议问题