且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从集合视图中删除项目?

更新时间:2022-11-02 09:46:02

你应该改变

self.collectionView.deleteItemsAtIndexPaths([indexPath.item])

self.collectionView.deleteItemsAtIndexPaths([indexPath])

deleteItemsAtIndexPaths 需要一个 NSIndexPath 数组,而不是一个数字数组.

deleteItemsAtIndexPaths expects an array of NSIndexPaths, not an array of numbers.

除此之外,如果您调用 deleteItemsAtIndexPaths,则不需要调用 reloadData - 这甚至会阻止任何动画的发生.

Besides that, if you call deleteItemsAtIndexPaths you don't need a call to reloadData - this will even prevent any animation from happening.

不要忘记更新您的数据源 - 必须从 people 数组中删除此人.

Don't forget to update your data source - the person has to be removed from the people array.

people.removeAtIndex(indexPath.item)

在调用 deleteItemsAtIndexPaths 之前 执行此操作.

Do this before calling deleteItemsAtIndexPaths.