2016-07-18 14 views
0

Hier ist mein Code-Schnipsel:Was kann den Fehler "Assertionsfehler in - [UICollectionViewData numberOfItemsBeforeSection:]" verursachen?

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]; 
}]; 

Was ist der Grund für diesen Fehler?

„Assertion Fehler in - [UICollectionViewData numberOfItemsBeforeSection:]“

Antwort

0

Ich denke, das Problem ist sehr einfach, wenn Sie vorsichtig sind. Bitte werfen Sie einen Blick auf die Absturzursache. "Assertionsfehler in - [UICollectionViewData numberOfItemsBeforeSection:]", Bedeutung ist der Abschnitt des Elements wurde nicht gefunden, also sollten Sie "NSIndexPath * indexPath = [NSIndexPath indexPathForItem: idx inSection: 0];" ersetzen "* NSIndexPath indexPath = [NSIndexPath indexPathWithIndex: idx];". Okey, Bingo

Verwandte Themen