我正在为UICollectionView编写自定义流布局.
我可以看到并滚动细胞.
我可以看到并滚动细胞.
问题是我无法显示节标题的补充视图.
所以,
- (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:
以返回每个补充视图的属性实例(除了每个单元格):
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.