njdehoog/NHBalancedFlowLayout — pull request #16 by rvirin (2014-02-14 09:56:07+00:00)
Title: Fix#14 Prevent from a crash when no footer or no header.

This methods should return nil for no footer or no header:

- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

And this method, declared in UICollectionViewDatasource (implemented in the Demo project) :

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *view = nil;

if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
}
else if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
view = nil; // [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
}
return view;
}

Note: The crash is not in this library, but in _createPreparedSupplementaryViewForElementOfKind: which is a private API of UICollectionView.