0

这是我的代码片段:

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:] 中的断言失败”</p>

4

1 回答 1

0

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

于 2016-07-18T08:38:35.637 回答