【问题标题】:Crash on collectionView.performBatchUpdates when trying to hide footer/header尝试隐藏页脚/页眉时,collectionView.performBatchUpdates 崩溃
【发布时间】:2015-05-10 16:29:57
【问题描述】:

我从分成页面的 API 获取数据,我使用 var hasMoreUsers: Bool 显示/隐藏页脚单元格

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
    if hasMoreUsers {
        return CGSizeMake(collectionView.contentSize.width, 50)
    } else {
        return CGSizeZero
    }
}

我设置hasMoreUsers = false并调用self.collectionView.performBatchUpdates添加数据的最后一页的代码刹车

这是错误

在调用self.collectionView.performBatchUpdates 时遇到此错误

*** Assertion failure in -[UICollectionViewData layoutAttributesForSupplementaryElementOfKind:atIndexPath:], /SourceCache/UIKit_Sim/UIKit-3347.44/UICollectionViewData.m:884

关注

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind: UICollectionElementKindSectionFooter at path <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}'

看起来它需要页脚尺寸,但我已经为它返回CGSizeZero,这应该是问题所在。真的很迷茫。

【问题讨论】:

    标签: ios objective-c swift collectionview


    【解决方案1】:

    提供非零大小,例如CGSizeMake(0.01, 0.01)

    这似乎是UICollectionView 中的一个错误。即使docs 指定返回 (0, 0) 的大小将导致不添加页脚,但这似乎仅在使用 reloadData 时有效。如果像你一样使用performBatchUpdates,它会崩溃。

    【讨论】:

      【解决方案2】:

      [[_collectionView collectionViewLayout] invalidateLayout];

      它解决了我的问题:隐藏页脚然后通过 performBatchUpdates 设置动画。

      答案来自Saren Inden

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-29
        • 2018-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多