I am writing a custom flow layout for a UICollectionView. I can see and scroll the cells.
The problem is that I can't make the supplementary view for the section header appear.
So,
- (UICollectionViewLayoutAttributes *)
layoutAttributesForSupplementaryViewOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
never gets called.
In the data source this method:
- (UICollectionReusableView *)
collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
also never gets called.
How can I make it so those methods are called?
EDIT: This is the layoutAttributesForElementsInRect:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSMutableArray * attributes = [NSMutableArray arrayWithCapacity:[[self.layoutInfo allKeys] count]];
for(NSIndexPath * indexPath in self.layoutInfo) {
UICollectionViewLayoutAttributes *itemAttributes = [self.layoutInfo objectForKey:indexPath];
if(CGRectIntersectsRect(rect, itemAttributes.frame)) {
[attributes addObject:itemAttributes];
}
}
return attributes;
}
So even with this the two methods for the supplementary view are not called.
You need to implement layoutAttributesForElementsInRect:
to return an attributes instance for each supplementary view (in addition to each cell):
Subclasses must override this method and use it to return layout information for all items whose view intersects the specified rectangle. Your implementation should return attributes for all visual elements, including cells, supplementary views, and decoration views.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With