我在Xcode 4.6中有一个集合视图的应用程序。我为每个集合视图单元添加了一个删除按钮,以便为用户提供删除单元的选项。从集合视图中删除集合视图单元格Xcode
尽管我意识到集合视图与表视图相似(并且我知道如何从表视图中删除单元格),但删除对象似乎在集合视图中工作方式不同。我查看了收集视图的类参考,但是作为iOS新手,我无法将他们的建议代码应用到我的项目中。该文档显示了删除单元格的以下建议代码:
[self.collectionView performBatchUpdates:^{
NSArray* itemPaths = [self.collectionView indexPathsForSelectedItems];
// Delete the items from the data source.
[self deleteItemsFromDataSourceAtIndexPaths:itemPaths];
// Now delete the items from the collection view.
[self.collectionView deleteItemsAtIndexPaths:tempArray];
} completion:nil];
因此,我将此代码添加到了我的按钮操作方法中。并且它在“temp array”中表示,我将集合视图所使用的数组替换为其数据源,以确定要显示的单元格数量。但我对“deleteItemsFromDataSourceAtIndexPaths:”是什么感到困惑。这是一个委托方法吗?编译器警告说它没有被声明。我不确定该从哪里出发。
任何帮助表示赞赏。
它似乎是从数据源数组中删除给定的NSIndexPaths的实用方法。这并不难。 – CodaFi 2013-04-04 16:07:15