Reputation: 1348
I've a UICollectionView that contains 10 sections and each sections have 2 cells. I am trying to delete a cell but I am getting this:
The number of sections contained in the collection view after the update (2) must be equal to the number of sections contained in the collection view before the update (2)
This is how I remove:
NSUInteger arrayLength = 1;
NSUInteger integerArray[] = {0,0};
NSIndexPath *aPath = [[NSIndexPath alloc] initWithIndexes:integerArray length:arrayLength];
[self.collectionFavs deleteItemsAtIndexPaths:[NSArray arrayWithObject:aPath]];
I just want to delete a cell or section with the cells. What is my mistake?
Upvotes: 4
Views: 4658
Reputation: 964
You should delete element from datasource array. F.e. if your method return 2 before deleting cell then after deleting it should return 1
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (notdeleted)
return 2;
else
return 1;
}
In fact if you return [array count] in this method, then you should remove 1 object from array before calling -deleteItemsAtIndexPaths
NSUInteger integerArray[] = {0,0};
NSIndexPath *aPath = [[NSIndexPath alloc] initWithIndexes:integerArray length:arrayLength];
[array removeObjectAtIndex:0];
[self.collectionFavs deleteItemsAtIndexPaths:[NSArray arrayWithObject:aPath]];
Upvotes: 3