gpt4 book ai didi

swift - 如何从 collectionview 重新加载部分

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:11 24 4
gpt4 key购买 nike

我试图通过 didSelect 方法从 collectionview 中删除一个单元格。

删除数据效果很好。

但是我得到这个:

reason: 'Invalid update: invalid number of sections. The number of sections contained in the collection view after the update (1) must be equal to the number of sections contained in the collection view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'

这是删除单元格函数:

func deleteMovie(cell: MoiveCollectionViewCell) {
var indexPath: NSIndexPath = self.collectionView!.indexPathForCell(cell)!
// remove and reload data
self.collectionView.deleteItemsAtIndexPaths([indexPath])
self.collectionView.reloadSections(NSIndexSet(index: indexPath.section))
}

numberOfSectionsInCollectionView函数:

 func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
//number_per_section = 3
if manager.movie_List.count % number_per_section == 0
{
return manager.movie_List.count / number_per_section
}
else {
return manager.movie_List.count / number_per_section + 1
}
}

我只想重新加载部分的数量。我应该添加什么?

最佳答案

您需要先更新数据源,然后再调用:

 collectionView.deleteItemsAtIndexPaths([indexPath])
collectionView.reloadSections(NSIndexSet(index: indexPath.section))

所以首先删除数据源模型中的对象(数组、字典等)。

那么你可以这样做:

 let indexSet = IndexSet(integer: indexPath.section)
collectionView.reloadSections(indexSet)

关于swift - 如何从 collectionview 重新加载部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38690065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com