繁体   English   中英

UICollectionView deleteItemsAtIndexPaths失败

[英]UICollectionView deleteItemsAtIndexPaths failure

- (void)deleteCell 
{
        [self.collectionViewMenu performBatchUpdates:^{

           [self.itemsArray removeObjectAtIndex:1];
           NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
           [self.collectionViewMenu deleteItemsAtIndexPaths:@[indexPath]];

    } completion:^(BOOL finished) {  }];
}

请帮助解决此问题,我在做什么错? 尝试删除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})'

我解决了删除页眉和页脚大小委托的问题。 问题是我没有返回页眉或页脚。

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;

setObjectForKey: object cannot be nil ,这意味着您尝试删除的单元格可能已被删除。 您应该尝试对其进行调试,并在调用delete时查看在集合视图中实际位于哪些索引路径的哪些视图。

您可能需要实现:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

在您的数据源中。 这帮了我大忙。

我只是尝试在performBatchUpdates之前调用collectionViewLayout.invalidateLayout() 然后,确保布局实现正确,并确保您没有为单元格返回负高度。 有关更多详细信息,请访问下面的GitHub链接。 https://github.com/ra1028/DifferenceKit/issues/13

它帮助我解决了错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM