[英]UICollectionView crash on cell insertion
我有一个带有页脚补充视图的UICollectionView。 通过collectionView的工作方式,可以在插入新单元格时将补充视图推离屏幕。 单元可以具有不同的水平尺寸。
如果插入了两个大单元格,并且辅助视图从屏幕上移开,则在两个大单元格之间插入一个小单元格会导致崩溃。
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:
atIndexPath (UICollectionElementKindCell,<NSIndexPath: 0xc00000000000000e>
{length = 1, path = 0}) was not retrieved by calling
-dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil ((null))'
我确定发生崩溃是因为补充视图为nil。 这是零,因为在
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
我检查一下将哪种元素传递给该方法。 当应用程序崩溃时,类型为UICollectionElementKindCell,对此我没有有效的响应。
所以,我的问题是双重的:
1)为什么用与我的补充视图不相关的一种方法调用viewForSupplementaryElementOfKind? 我希望UICollectionView应该仅尝试从此方法获取补充视图信息。
2)如何避免这种崩溃?
目前尚不清楚原因,但是此崩溃已通过覆盖方法解决了
- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
并返回true,并删除对插入方法中的invalidateLayout的调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.