本文介绍了没有调用layoutAttributesForSupplementaryViewOfKind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为UICollectionView编写自定义流布局.我可以看到并滚动这些单元格.

I am writing a custom flow layout for a UICollectionView.I can see and scroll the cells.

问题是我无法显示节标题的补充视图.

The problem is that I can't make the supplementary view for the section header appear.

所以

- (UICollectionViewLayoutAttributes *)
      layoutAttributesForSupplementaryViewOfKind:(NSString *)kind 
      atIndexPath:(NSIndexPath *)indexPath

从不打电话.

在数据源中,此方法:

- (UICollectionReusableView *)
      collectionView:(UICollectionView *)collectionView 
      viewForSupplementaryElementOfKind:(NSString *)kind 
      atIndexPath:(NSIndexPath *)indexPath

也从未被呼叫.

我怎样才能使这些方法被调用?

How can I make it so those methods are called?

这是layoutAttributesForElementsInRect:

This is the 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;
}

因此,即使这样,也不会调用用于补充视图的两种方法.

So even with this the two methods for the supplementary view are not called.

推荐答案

您需要实现 layoutAttributesForElementsInRect: 返回每个补充视图的属性实例(除了每个单元格):

You need to implement layoutAttributesForElementsInRect: to return an attributes instance for each supplementary view (in addition to each cell):

这篇关于没有调用layoutAttributesForSupplementaryViewOfKind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:14