Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layoutAttributesForSupplementaryViewOfKind not called

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.

like image 225
zumzum Avatar asked Aug 19 '14 20:08

zumzum


1 Answers

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.

like image 150
rob mayoff Avatar answered Oct 19 '22 06:10

rob mayoff