【问题标题】:'no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind' -layoutAttributesForSupplementaryElementOfKind 没有 UICollectionViewLayoutAttributes 实例
【发布时间】:2014-09-28 03:16:32
【问题描述】:

我遇到了这个崩溃:

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

这里是performBatchUpdates

    // Reload just the indexPath that loaded
    [UIView animateWithDuration:0 animations:^{
        [self.collectionView performBatchUpdates:^{
            [self.collectionView reloadItemsAtIndexPaths:paths];
        } completion:nil];
    }];

我正在使用UICollectionViewFlowLayout

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
_collectionViewLayout = layout;

我不明白为什么会这样。我正在重新加载我的一个项目单元格,它指的是补充视图(这是一个标题视图)。


编辑

跟下面的有关系吗?

如果我在- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 中注销indexPath,我会接到第一个电话:

-[WSImageViewerController collectionView:cellForItemAtIndexPath:] [Line 318] indexPath = <NSIndexPath: 0x16d5c990> {length = 2, path = 0 - 0}

调用- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPathindexPath 日志是:

-[WSImageViewerController collectionView:viewForSupplementaryElementOfKind:atIndexPath:] [Line 399] indexPath = <NSIndexPath: 0x15691570> {length = 2, path = 0 - 0}

两个 indexPath 都是 0 - 0。跟这个有关系吗?


编辑两个

这是崩溃时发生的情况。它试图在标题视图上加载常规项目单元格。中间有一个很大的UIActivityIndi​​catorView,是从补充的header view里来的,所以我知道已经添加了。

【问题讨论】:

    标签: objective-c uicollectionview


    【解决方案1】:

    这是旧的,我不知道你是否是这种情况,但我想留下它以防有人遇到同样的问题。如果您为 UICollectionViewController 使用自定义布局,请确保您为补充视图类型使用正确的名称。例如,我使用CHTCollectionViewWaterfallLayout,而补充视图种类名称必须使用CHTCollectionElementKindSectionHeader 而不是UICollectionElementKindSectionHeader

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多