我收到一个错误:
Assertion failure in -[UICollectionViewData numberOfItemsBeforeSection:],/SourceCache/UIKit_Sim/UIKit-2935.137/UICollectionViewData.m
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items before section 2 when there are only 1 sections in the collection view'
当我尝试重新加载 collectionview 时,它会在添加新部分时起作用,但是当我尝试删除它们时会引发异常。
更新:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return object.count;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
if([sortString isEqualToString:@"title"])
return [Obj.ordered allKeys].count;
else
return 1;
}
最佳答案
在 删除行或节之前,您必须从 数据源 数组中删除项目。如果您的方法在删除部分之前返回 1
,那么在删除之后它应该返回 0
。
关于ios - 尝试重新加载数据时 UICollectionView 中的断言失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24754348/