0
我有一個頁腳補充視圖的UICollectionView。 collectionView的工作方式,可以在插入新單元格時將補充視圖推到屏幕外。細胞可以有不同的水平尺寸。單元插入UICollectionView崩潰
如果插入兩個大單元格並將補充視圖從屏幕上移開,則在兩個較大單元格之間插入一個小單元格會導致崩潰。
*** 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)如何避免這種崩潰?
你可以返回任何視圖,但你已經使用了頁腳視圖,所以也許試試吧 – Misha