簡體   English   中英

單元格插入時UICollectionView崩潰

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM