The idea:
We need to use 2 collection views in 1 view controller. First collection view has no header and the second has a header.
So we need to register header(nib) for the second collection view controller only.
By calling this code:
But the app crash after the above method invoke:
How you fix it?
Issues come from thie method below that set the header’s size for collection view:
(CGSize)collectionView:(UICollectionView *)collectionView layout: (UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
It will call the method below for providing header to all collection view:
(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
Note: our first collection don’t register the header class but the method invoke for providing header for the first collection view too.
You can fix it by providing the header’s size of the first collection view with size 0.
Example: