【问题标题】:What can cause the error “Assertion failure in -[UICollectionViewData numberOfItemsBeforeSection:]”?什么会导致错误“-[UICollectionViewData numberOfItemsBeforeSection:] 中的断言失败”?
【发布时间】:2016-07-18 08:33:31
【问题描述】:

这是我的代码 sn-p:

NSIndexSet *indexSet =  self.selectedIndexSet;
__block SGPhotoSelectorCell *cell;

[indexSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {

    NSLog(@"%lu", (unsigned long)idx);
    ***NSIndexPath *indexPath = [NSIndexPath indexPathWithIndex:idx];***

    cell = (SGPhotoSelectorCell *)[collectionView cellForItemAtIndexPath:indexPath];
    cell.numLabel.text = [NSString stringWithFormat:@"%lu", (unsigned long)idx];

    [collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
}];

这个错误的原因是什么?

“-[UICollectionViewData numberOfItemsBeforeSection:] 中的断言失败”

【问题讨论】:

    标签: ios uicollectionview nsindexset


    【解决方案1】:

    如果你小心点,我认为这个问题很简单。请再次查看崩溃的原因。 “Assertion failure in -[UICollectionViewData numberOfItemsBeforeSection:]”,意思是没有找到item的section,所以你应该使用“NSIndexPath *indexPath = [NSIndexPath indexPathForItem:idx inSection:0];”替换“*NSIndexPath indexPath = [NSIndexPath indexPathWithIndex:idx];”。好吧,宾果游戏

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-19
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      • 2018-07-30
      • 2011-05-29
      • 1970-01-01
      相关资源
      最近更新 更多