Ich erstelle eine benutzerdefinierte Layoutsammlungsansicht. Ich habe 2 zusätzliche Ansichten pro Artikel in meiner Sammlung. Und wenn ich ein Element löschen möchte, wird meine layoutAttributesForSupplementaryViewOfKind:atIndexPath:
Implementierung mit zusätzlichen Ansichten aufgerufen, die nicht mehr existieren sollten. Das bedeutet, dass ich einen Indexpfad erhalte, der meiner Datenquelle nicht richtig zugeordnet wird, und ich bekomme ein Problem außerhalb der Grenzen.Zusätzliche Ansichten werden nicht gelöscht
Ich habe etwas Logging gemacht und was in der ersten Instanz folgt ist die korrekte und logische Art und Weise, wie die Sammlungsansicht berechnet wird, wenn wir mit einigen Daten beginnen oder wenn wir ein Element in die Sammlungsansicht einfügen.
Der zweite Satz von Protokollen ist, wenn ich deleteItemsAtIndexPaths:
nach dem Löschen eines Objekts aus meiner Datenquelle.
Mein layoutAttributesForElementsInRect:
sieht wie folgt aus:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSMutableArray* attributes = [NSMutableArray array];
for (NSInteger i = 0 ; i < [self.myData count]; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
NSLog(@"%@ indexPath.row:%d", NSStringFromSelector(_cmd), indexPath.row);
UICollectionViewLayoutAttributes *att = [self layoutAttributesForItemAtIndexPath:indexPath];
[attributes addObject:att];
UICollectionViewLayoutAttributes *att_supp = [self layoutAttributesForSupplementaryViewOfKind:@"one_kind" atIndexPath:indexPath];
[attributes addObject:att_supp];
UICollectionViewLayoutAttributes *linesAttr = [self layoutAttributesForSupplementaryViewOfKind:@"another_kind" atIndexPath:indexPath];
[attributes addObject:linesAttr];
}
return attributes;
}
Initial-Protokolle (korrekt und logisch):
MyApp[18546:70b] layoutAttributesForElementsInRect: indexPath.row:0
MyApp[18546:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:0
MyApp[18546:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:0
MyApp[18546:70b] layoutAttributesForElementsInRect: indexPath.row:1
MyApp[18546:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:1
MyApp[18546:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:1
MyApp[18546:70b] layoutAttributesForElementsInRect: indexPath.row:2
MyApp[18546:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:2
MyApp[18546:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:2
Nach ein Element zu löschen:
MyApp[18633:70b] layoutAttributesForElementsInRect: indexPath.row:0
MyApp[18633:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:0
MyApp[18633:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:0
MyApp[18633:70b] layoutAttributesForElementsInRect: indexPath.row:1
MyApp[18633:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:1
MyApp[18633:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:1
MyApp[18633:70b] layoutAttributesForSupplementaryViewOfKind:atIndexPath: indexPath.row:2
Wie Sie sehen können layoutAttributesForSupplementaryViewOfKind:atIndexPath:
ist genannt, aber unter Umgehung layoutAttributesForElementsInRect:
Weiß jemand, was schief gehen könnte?
Hört sich gut an, ich werde es versuchen, danke. – Daniel
einige Male funktioniert diese Antwort, manchmal nicht, immer noch einige Abstürze – kokemomuke
Als ich das Objekt in der Sammlung entfernte, fragte das Layout immer nach einer alten ergänzenden Ansicht. 'indexPathsToDeleteForSupplementaryViewOfKind' war die Methode, die mir fehlte. Danke vielmals! –