gpt4 book ai didi

ios - layoutAttributesForSupplementaryViewOfKind 未调用

转载 作者:可可西里 更新时间:2023-11-01 03:08:12 26 4
gpt4 key购买 nike

我正在为 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com