Reputation: 404
- (void)deleteCell
{
[self.collectionViewMenu performBatchUpdates:^{
[self.itemsArray removeObjectAtIndex:1];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[self.collectionViewMenu deleteItemsAtIndexPaths:@[indexPath]];
} completion:^(BOOL finished) { }];
}
Please help to solve this problem, what am I doing wrong? I got this error after trying to delete an item in my collectionView.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: <_UICollectionViewItemKey: 0x8d705e0> Type = SV Kind = UICollectionElementKindSectionHeader IndexPath = <NSIndexPath: 0x8d6f4b0> {length = 2, path = 0 - 0})'
Upvotes: 1
Views: 2590
Reputation: 6593
I just try to call collectionViewLayout.invalidateLayout()
before performBatchUpdates
. Then make sure the layout implementation are correctly and make sure that you are not returning negative height for cell. For more detail you can visit below GitHub link.
https://github.com/ra1028/DifferenceKit/issues/13
It helped me to fix the error.
Upvotes: 0
Reputation: 3509
You probably need to implement:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
in your dataSource. This did the trick for me.
Upvotes: 0
Reputation: 404
I solve the problem with remove the header and footer size delegates. the problem was in the fact that I do not return a header or footer.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;
Upvotes: 3
Reputation: 5616
setObjectForKey: object cannot be nil
means that the cell you are trying to delete is possibly already been deleted.
You should try to debug it and see when you call the delete what views at what index paths are actually in your collection view.
Upvotes: 0