Falha ao coletar a exclusão da célula por exibição de "UICollectionViewLayoutAttributes"
Minha fonte de dados é uma matriz bidimensional porque tenho emojis divididos em seções.
eg. [[a,b,c,d],[e,f,g],[h,j,k,l,m]]
Meu código de exclusão de célula -
func deleteEmoji(at indexPath: IndexPath) {
// Get the bad emoji
let emojiToBeDeleted = emojisArray[indexPath.section][indexPath.row]
// Delete the emoji from datasource and collection view
emojisArray[indexPath.section].remove(at: indexPath.row)
stickerCollectionView.deleteItems(at: [indexPath])
// Delete the section from datasource and collection view as its emoji count is zero
if emojisArray[indexPath.section].count == 0 {
emojisArray.remove(at: indexPath.section)
stickerCollectionView.deleteSections(IndexSet(integer: indexPath.section)) // Crashing here :(
sectionCollectionView.reloadData()
}
// Delete the bad emoji
emojiToBeDeleted.delete()
// Undo the deletion mode as all emoji's are deleted
if emojisArray.count == 0 {
isDeletionMode = false
}
}
Eu também tenho rodapés para cada seção, exceto a última seção, pois tenho isso emUICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionFooter:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: Identifier.footer, for: indexPath)
return headerView
default:
assert(false, "Unexpected element kind")
}
}
e emUICollectionViewDelegate
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
switch collectionView {
case stickerCollectionView:
if section == emojisArray.count - 1 {
return CGSize.zero
}
return CGSize(width: collectionView.bounds.size.width, height: 15)
default:
return CGSize.zero
}
}
Erro -
*** Finalizando o aplicativo devido à exceção não capturada 'NSInternalInconsistencyException', motivo: 'nenhuma instância UICollectionViewLayoutAttributes para -layoutAttributesForSupplementaryElementOfKind: UICollectionElementKindSectionFooter no caminho {length = 2, path = 0 - 0}'
Estou recebendo esse erro ao excluir células. E acidente nem sempre acontece, é bastante aleatório.
sectionCollectionView
é completamente diferente UICollectionView.