作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在为 UICollectionView 编写自定义流布局。我可以看到并滚动单元格。
问题是我无法显示节标题的补充 View 。
所以,
- (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;
}
因此即使这样,也不会调用补充 View 的两个方法。
最佳答案
您需要实现 layoutAttributesForElementsInRect:
为每个补充 View (除了每个单元格)返回一个属性实例:
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.
关于ios - layoutAttributesForSupplementaryViewOfKind 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25392633/
我正在为 UICollectionView 编写自定义流布局。我可以看到并滚动单元格。 问题是我无法显示节标题的补充 View 。 所以, - (UICollectionViewLayoutAttri
我是一名优秀的程序员,十分优秀!