I'm having issues updating a collection view when receiving those updates via KVO.
e.g. for deletion I perform the following:
dispatch_async(dispatch_get_main_queue(), ^{
NSUInteger index = [self.albumObjects indexOfObject:oldObject];
NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0];
[self.dataSource removeObjectAtIndex:index];
[self.collectionView deleteItemsAtIndexPaths:@[indexPath]];
}
The above gives me the error:
attempt to delete item 0 from section 0 which only contains 0 items before the update
Ok... so lets remove from the data source afterwards then which then returns the following error:
dispatch_async(dispatch_get_main_queue(), ^{
NSUInteger index = [self.albumObjects indexOfObject:oldObject];
NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0];
[self.collectionView deleteItemsAtIndexPaths:@[indexPath]];
[self.dataSource removeObjectAtIndex:index];
}
However I now get the following error instead:
Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).
So it seems I can't win? What am I doing wrong here?