【发布时间】:2017-02-12 23:15:50
【问题描述】:
我有一个带有页脚补充视图的 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))'
我已确定发生崩溃是因为补充视图为零。它是零,因为在
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
我检查了什么样的元素已经交给了方法。当应用程序崩溃时,类型是 UICollectionElementKindCell,对此我没有有效的响应。
所以,我的问题是双重的:
1) 为什么 viewForSupplementaryElementOfKind 的调用类型与我的补充视图无关?我希望 UICollectionView 应该只尝试从此方法获取补充视图信息。
2) 如何避免这种崩溃?
【问题讨论】:
-
你可以从它返回任何视图,但你已经在使用页脚视图,所以也许尝试 dequeing 它
标签: ios uicollectionview uicollectionreusableview