layoutAttributesForSupplementaryViewOfKind没有被调用
我正在为UICollectionView编写自定义stream布局。 我可以看到并滚动单元格。
问题是我不能使节标题的补充视图出现。
所以,
- (UICollectionViewLayoutAttributes *) layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
永远不会被调用。
在数据源中这个方法:
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
也永远不会被调用 。
我怎样才能使这些方法被称为?
编辑:这是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; }
所以即使这样,补充视图的两种方法也不会被调用。
您需要实现layoutAttributesForElementsInRect:
为每个补充视图(除了每个单元格)返回一个属性实例:
子类必须重写此方法,并使用它返回其视图与指定矩形相交的所有项目的布局信息。 您的实现应该返回所有视觉元素的属性,包括单元格,补充视图和装饰视图。