CollectionView + UIKit Dynamics在performBatchUpdates上崩溃:

 spring709272032 发布于 2023-02-11 05:54

我遇到了一个奇怪的崩溃并试图整天修复它.我有一个自定义UICollectionViewLayout,它基本上增加了细胞的重力和碰撞.

实施效果很好!当我尝试使用以下命令删除一个单元格时会出现问题:[self.collectionView performBatchUpdates:].

它给了我以下错误:

2013-12-12 21:15:35.269 APPNAME[97890:70b] *** Assertion failure in -[UICollectionViewData validateLayoutInRect:], /SourceCache/UIKit_Sim/UIKit-2935.58/UICollectionViewData.m:357

2013-12-12 20:55:49.739 APPNAME[97438:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView recieved layout attributes for a cell with an index path that does not exist:  {length = 2, path = 0 - 4}'

我的模型处理正确,我可以看到它从中删除项目!

要删除的项的indexPaths正在对象之间正确传递.collectionView更新没有崩溃的唯一时间是我删除它上面的最后一个单元格,否则,崩溃就会发生.

这是我用来删除单元格的代码.

- (void)removeItemAtIndexPath:(NSIndexPath *)itemToRemove completion:(void (^)(void))completion
{
    UICollectionViewLayoutAttributes *attributes = [self.dynamicAnimator layoutAttributesForCellAtIndexPath:itemToRemove];

    [self.gravityBehaviour removeItem:attributes];
    [self.itemBehaviour removeItem:attributes];
    [self.collisionBehaviour removeItem:attributes];

    [self.collectionView performBatchUpdates:^{
        [self.fetchedBeacons removeObjectAtIndex:itemToRemove.row];
        [self.collectionView deleteItemsAtIndexPaths:@[itemToRemove]];
    } completion:nil];   
}

处理单元属性的CollectionView委托是下面的基本委托.

- (CGSize)collectionViewContentSize
{
    return self.collectionView.bounds.size;
}

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    return [self.dynamicAnimator itemsInRect:rect];
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];
}

我已经尝试过的事情没有成功: - 使布局无效 - 重新加载数据 - 从UIDynamicAnimator中删除行为并在更新后再次添加它们

任何见解?

此存储库中提供了有问题的源代码.请检查一下.代码库

最好.乔治.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有