Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios supplementaryViewForElementKind的结果无效_Ios_Objective C_Collections_Uicollectionview_Uikit - Fatal编程技术网

Ios supplementaryViewForElementKind的结果无效

Ios supplementaryViewForElementKind的结果无效,ios,objective-c,collections,uicollectionview,uikit,Ios,Objective C,Collections,Uicollectionview,Uikit,每当需要在layoutSubviews()中使底部边缘的布局无效时,我会尝试重置我的collectionView的子视图框架和layouttributes。然而,每隔一段时间,就有0.5%的时间。我的错误导致崩溃: 致命异常:NSInternalInconsistencyException 调用-dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath(UICollectionElementKindSectio

每当需要在
layoutSubviews()
中使底部边缘的布局无效时,我会尝试重置我的
collectionView
的子视图框架和
layouttributes
。然而,每隔一段时间,就有0.5%的时间。我的错误导致崩溃:

致命异常:NSInternalInconsistencyException 调用-dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath(UICollectionElementKindSectionHeader,{length=2,path=14-0})未检索从-collectionView:ViewForSupplmentalElementOfKind:atIndexPath返回的视图,或者该视图为nil()

我猜这与普通的
UICollectionReusableView()
有关,每当节不需要标题时,我都会在
dequeueSupplementaryView
中返回。我已经盯着这个看了一段时间,所以我想也许有人能帮上忙

for (UICollectionViewLayoutAttributes *attributes in attributesInBounds) {
    if (!CGRectIntersectsRect(attributes.frame, self.bounds)) {
        continue;
    }

    UICollectionReusableView *view = nil;

    switch (attributes.representedElementCategory) {
        case UICollectionElementCategoryCell:
            view = [self cellForItemAtIndexPath:attributes.indexPath];
            break;
        case UICollectionElementCategorySupplementaryView:
            view = [self supplementaryViewForElementKind:attributes.representedElementKind atIndexPath:attributes.indexPath];
            break;
        default:
            break;
        }

    [view setFrame:attributes.frame];
    [view applyLayoutAttributes:attributes];
}

我也在猜测,但我怀疑仍有一些批更新正在执行。。。你能始终如一地重现错误吗?如何修复它。。。不确定,但可以安排在main上执行的操作,以确保在正在进行的任何操作完成后运行。@skaak滚动集合视图或旋转屏幕时,似乎会发生这种情况。这可能是关于如何调用/处理
.layoutSubviews
的线程问题吗?不过,我认为苹果现在已经遇到并解决了这个问题。在iOS版本中似乎发生了这样的事情不要给苹果太多的信任——这是另一个我为了空间而不得不删除的故事。不管怎样,我还是在这里猜测,但我认为解决你问题的方法如下。我理解,你的问题是,有时候你不想要标题单元格,有时候你想要一个。然后为什么不重写委托中的
collectionView:layout:referenceSizeForHeaderInstruction:
。然后,您可以在其中构建逻辑,并根据该逻辑返回0或某个值,如果视图本身没有重新绘制,您还可以请求刷新。我认为这是更好的方法。