【发布时间】:2013-11-29 17:41:49
【问题描述】:
我在使用 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];,但我想知道其他地方是否发生了一些奇怪的事情......
感谢您提供的任何帮助。
【问题讨论】:
-
if(insertSections != nil) { [self.collectionView insertSections:insertSections]; }
标签: ios objective-c ios7 uicollectionview