Ros*_*mes 11 objective-c ios uicollectionview uicollectionviewlayout uikit-dynamics
好的基本概述.我有一个UICollectionView我需要支持通过该performBatchUpdates:方法添加和删除项目.如果我使用标准UICollectionViewFlowLayout,它工作正常.
但是,当我尝试使用UICollectionViewFlowLayout由a驱动的时UIDynamicAnimator,我一打电话就会崩溃performBatchChanges.
在我的自定义UICollectionViewFlowLayout类中,prepareForCollectionViewUpdates:永远不会调用该方法.UICollectionViewFlowLayout我使用的自定义基于此示例.
崩溃后的控制台输出是......
*** 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
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
aki*_*108 13
尝试
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewLayoutAttributes *layoutAttributes = [self.dynamicAnimator layoutAttributesForCellAtIndexPath:indexPath];
if(!layoutAttributes) {
layoutAttributes = [super layoutAttributesForItemAtIndexPath:indexPath];
}
return layoutAttributes;
}
Run Code Online (Sandbox Code Playgroud)
执行时performBatchUpdates,如果不能看到将由update创建的单元格,则[self.dynamicAnimator layoutAttributesForCellAtIndexPath: 返回nil.所以现在就回来super(或许UICollectionViewFlowLayout)layoutAttributes.当细胞即将展示时,UIDynamicAnimator将为您完成工作.
| 归档时间: |
|
| 查看次数: |
5480 次 |
| 最近记录: |