我使用UICollectionView收到错误如下:
2013-11-29 17:29:07.832 Clients[34200:70b]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '*** setObjectForKey: object cannot be nil
(key: <_UICollectionViewItemKey: 0x8da14f0>
Type = DV ReuseID = (null) IndexPath = (null))'
代码如下,其中我基本上有两个NSMutableArrays - 一个包含所有条目,另一个用于将条目减少到一个部分 - 在这一点上,我将所有缺少的部分添加回来(希望有道理。)
[self.collectionView performBatchUpdates:^{
NSString *selectedMarketSector = [[[[_marketSectors objectAtIndex:0] clients] objectAtIndex:0] clientMarketSector];
NSMutableIndexSet *insertSections = [[NSMutableIndexSet alloc] init];
for (TBMarketSector* sector in _allMarketSectors) {
if (![[[[sector clients] objectAtIndex:0] clientMarketSector ] isEqualToString:selectedMarketSector]) {
[insertSections addIndex:[_allMarketSectors indexOfObject:sector]];
}
}
_marketSectors = [self.allMarketSectors mutableCopy];
[self.collectionView insertSections:insertSections];
} completion:^(BOOL finished) {
[self setLayoutStyle:TBLayoutStacks animated:YES];
}];
“看起来”导致问题的一行是[self.collectionView insertSections:insertSections];
,但我想知道其他地方是否有奇怪的事情......
感谢您提供的任何帮助。
答案 0 :(得分:1)
信不信由你,似乎这个特殊问题实际上与我不想要的UICollectionElementKindSectionFooter
有关。
我应该提到这只是iOS7的一个问题(这不是我转换到iOS 7后收集视图的第一个问题)。
无论如何,我的自定义UICollectionViewFlowLayout
实现了- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
方法,并为所有补充视图返回了一些属性。
要解决此特定问题,我需要添加以下内容:
if ([kind isKindOfClass:[UICollectionElementKindSectionFooter class]])
return nil;
感谢。
答案 1 :(得分:0)
这种崩溃可能是因为方法
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
您尝试进入dequeueReusableSupplementaryView(ofKind:
-当类型为elementKindSectionFooter时,类型为elementKindSectionHeader的视图。
检查当前类型的笔尖寄存器。
谢谢。