-layoutAttributesForSupplementaryElementOfKind没有UICollectionViewLayoutAttributes实例: [英] no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind:
问题描述
标题是我得到的错误,我不知道为什么,但这里有一些信息,所以希望有人在这里可以解释我。
The title is the error I'm getting and I have no idea why, but here is some information so hopefully someone on here can elucidate me.
我有子类 UICollectionViewFlowLayout
因为这可以节省我在 prepareLayout
中计算单元格的帧(也许这是一个问题?)。然后我使用 UICollectionViewLayoutAttributes
信息来计算一个补充视图,我得到了我想要的布局。
I have subclassed UICollectionViewFlowLayout
as this saves me calculating the frames for the cell's myself (perhaps this is an issue?) in prepareLayout
. I then use the UICollectionViewLayoutAttributes
information to calculate a supplementary view that over lays it, I get the layout I desire.
我使用 performBatchUpdates:completion:
来添加,删除和更新视图。插入工作正常,但删除项目是出现标题中显示的错误。
I use performBatchUpdates:completion:
to add,remove and update the view. Insertion works fine, however deleting items is when the error shown in the title appears.
所以我知道为什么错误发生但我不知道为什么它甚至应该发生。通过一个导致问题的场景的示例来澄清
So I know why the error is happening but i don't know why it should even be happening. To clarify with an example going through a scenario that causes the issue
- 从1个项目开始,包含1个补充视图1个部分
- 再添加两个项目(
prepareLayout
查看包含3个补充视图的3个项目) - 删除项目(
prepareLayout
看到2个视图,带有2个补充视图) -
layoutAttributesForSupplementaryViewOfKind:atIndexPath:
被调用询问对于部分的索引路径的属性:0和项目:2 - 崩溃,因为它要求第三个补充视图的属性,即使它之前称为准备布局设置最多2个项目和2个补充意见
- 举手辞职和绝望
- Start with 1 item with 1 supplementary view 1 section
- Add two more items (
prepareLayout
sees 3 items with 3 supplementary views) - Delete item (
prepareLayout
sees 2 views with 2 supplementary views) layoutAttributesForSupplementaryViewOfKind:atIndexPath:
is called asking for attributes for index path with section:0 and item:2- Crash because it asked for attributes for a third supplementary view even though earlier it called prepare layout setting up 2 items and 2 supplementary views
- Throw hands up in resignation and despair
所以据我所知,违规函数是:
so the offending function as far as i can tell is:
- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
{
return self.layoutInfo[elementKind][indexPath];
}
这当然是由 UICollectionView
所以我不知道为什么它要求在索引路径上的补充视图。
which of course is called automagically by the internal networking of UICollectionView
so I have no clue as to why it's asking for that supplementary view at that index path.
任何人都有任何想法?也许这就是我如何使用 performBatchUpdates:completion:
但删除工作正常,直到添加补充视图。我可以根据需要提供更多的代码/解释。
Anyone got any ideas? Perhaps it's how i use performBatchUpdates:completion:
but deletion worked fine until adding supplementary views. I can provide more code/explanation as necessary.
推荐答案
我搜索论坛寻找答案并找到了一些建议。他们都没有给我我需要的救援,最终为了满足最后期限,我完全放弃了补充意见的使用。
I scoured the forums looking for an answer and came across a few suggestions. None of them gave me the succour I needed, and eventually in the interest of meeting deadlines, I dropped the use of supplementary views altogether.
几个星期后出于好奇我再次环顾四周,最终发现了以下帖子,现在我又回到了再次使用补充意见。
A few weeks later out of curiosity I looked around again and eventually came across the following post and now I'm back to using supplementary views again.
所以,不要忘记退回你的:
So, don't forget to return your:
- (NSArray<NSIndexPath *> *)indexPathsToDeleteForSupplementaryViewOfKind:(NSString *)elementKind
{
return self.removedIndexPaths;
}
到您的收藏夹视图布局。
to your collection view layout.
这篇关于-layoutAttributesForSupplementaryElementOfKind没有UICollectionViewLayoutAttributes实例:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!