我有我自己的自定義UICollectionViewLayout,增加了在給定的部分每行自定義標題,當我從那個部分我得到的刪除項目下列崩潰:從UICollectionView一節刪除行似乎並沒有刪除相關頭
***終止應用程序由於未捕獲的異常 'NSInternalInconsistencyException',原因: '的-layoutAttributesForSupplementaryElementOfKind沒有UICollectionViewLayoutAttributes實例:UICollectionElementKindSectionHeader在路徑長度{= 2,路徑= 2 - 0}'
這對我來說毫無意義。我剛剛刪除了2 - 0行,爲什麼它試圖從我的佈局類中請求標題?
這是我刪除行的代碼:
collectionView?.performBatchUpdates({
self.trackControllers.remove(at: index)
if self.collectionView?.numberOfItems(inSection: 2) > index {
self.collectionView?.deleteItems(at: [IndexPath(row: index, section: 2)])
}
})
不要緊,如果該部分是刪除後空,或者有其它行,它似乎仍然請求報頭我剛剛刪除的那一行。
謝謝你對「indexPathsToDeleteForSupplementaryView」的提示。引用文檔「例如,當某個部分被刪除時,您可能需要刪除與該部分相關的補充視圖。」當我刪除部分時,我可能會刪除部分標題。我可能... –