没有调用layoutAttributesForSupplementaryViewOfKind [英] layoutAttributesForSupplementaryViewOfKind not called

查看:73
本文介绍了没有调用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.

推荐答案

您需要实现

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

子类必须重写此方法,并使用它返回其视图与指定矩形相交的所有项目的布局信息.您的实现应返回所有可视元素的属性,包括单元格,补充视图和装饰视图.

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆