ios – 使用具有UIDynamics的UICollectionViewFlowLayout [UICollectionView performBatchUpdates:]

ios – 使用具有UIDynamics的UICollectionViewFlowLayout [UICollectionView performBatchUpdates:],第1张

概述好的基本概述我有一个UICollectionView,我需要支持通过performBatchUpdates:方法添加和删除项目.如果我使用标准的UICollectionViewFlowLayout,它工作正常. 但是,当我尝试使用由UIDynamicAnimator驱动的UICollectionViewFlowLayout时,一旦我调用performBatchChanges,我就会遇到崩溃. 在我 好的基本概述我有一个UICollectionVIEw,我需要支持通过performBatchUpdates:方法添加和删除项目.如果我使用标准的UICollectionVIEwFlowLayout,它工作正常.

但是,当我尝试使用由UIDynamicAnimator驱动的UICollectionVIEwFlowLayout时,一旦我调用performBatchChanges,我就会遇到崩溃.

在我的自定义UICollectionVIEwFlowLayout类中,prepareForCollectionVIEwUpdates:方法从未被调用.我使用的自定义UICollectionVIEwFlowLayout基于this sample.

崩溃后的控制台输出是…

*** Assertion failure in -[UICollectionVIEwData layoutAttributesForItemAtIndexPath:],/SourceCache/UIKit/UIKit-2903.23/UICollectionVIEwData.m:581*** Terminating app due to uncaught exception 'NSInternalinconsistencyException',reason: 'no UICollectionVIEwLayoutAttributes instance for -layoutAttributesForItemAtIndexPath: <NSIndexPath: 0xc000000000028096> {length = 2,path = 2 - 5}'*** First throw call stack:libc++abi.dylib: terminating with uncaught exception of type NSException

有任何想法吗?

解决方法 尝试
- (UICollectionVIEwLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {    UICollectionVIEwLayoutAttributes *layoutAttributes = [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];    if(!layoutAttributes) {        layoutAttributes = [super layoutAttributesForItemAtIndexPath:indexPath];    }    return layoutAttributes;}

当执行performBatchUpdates时,[self.dynamicAnimator layoutAttributesForCellAtIndexPath:如果由update创建的单元格不可见,则返回nil.所以只是返回超级(也许UICollectionVIEwFlowLayout)’现在的layoutAttributes.当要显示的单元格时,UIDynamicAnimator将为您做这项工作.

总结

以上是内存溢出为你收集整理的ios – 使用具有UIDynamics的UICollectionViewFlowLayout [UICollectionView performBatchUpdates:]全部内容,希望文章能够帮你解决ios – 使用具有UIDynamics的UICollectionViewFlowLayout [UICollectionView performBatchUpdates:]所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1098158.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存