我正在为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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。