尝试隐藏页脚/标题时遇到collectionView.performBatchUpdates崩溃

时间:2015-05-10 16:29:58

标签: ios objective-c swift collectionview

我从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,这应该是问题所在。真的很困惑。

2 个答案:

答案 0 :(得分:5)

提供非零大小,例如UICollectionView

这似乎是reloadData中的错误。尽管docs指定返回大小为(0,0)将导致没有添加页脚,但这只在使用performBatchUpdates时才起作用。如果按原样使用.json,则会崩溃。

答案 1 :(得分:1)

[[_ collectionView collectionViewLayout] invalidateLayout];

它解决了我的问题:隐藏页脚然后通过performBatchUpdates进行动画处理。

并且答案来自Saren Inden

相关问题