iOS   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – layoutAttributesForSupplementaryViewOfKind未调用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在为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:以返回每个补充视图的属性实例(除了每个单元格):

大佬总结

以上是大佬教程为你收集整理的ios – layoutAttributesForSupplementaryViewOfKind未调用全部内容,希望文章能够帮你解决ios – layoutAttributesForSupplementaryViewOfKind未调用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: