2015-10-27 43 views
0

在最简单的例子,我可以证明,我试过,我试图从UICollectionView删除项目,但我总是得到一个错误的不一致:我该如何做到这一点UICollectionView.deleteItemsAtIndexPaths在Swift中正确?

'NSInternalInconsistencyException', reason: 'attempt to delete item 0 from section 1, but there are only 1 sections before the update'

self.collectionView!.performBatchUpdates({ 
    self.collectionView?.deleteItemsAtIndexPaths([NSIndexPath(forItem: 0, inSection: 1) ]) 
}, completion: nil) 

如果你能告诉我一个完整的方法的完整工作示例,这将是有益的。

+0

只是为了澄清,你其实只需要在您的收藏视图中的一个部分?如果是这样,你需要NSIndexPath(forItem:0,inSection:0) – geraldWilliam

回答

0

部分从零开始编号。该错误消息告诉您,您尝试从第1部分中删除项目,但集合视图中只有一个部分。由于只有一个部分,该部分是数字0

也许你想这样做:

self.collectionView?.deleteItemsAtIndexPaths([NSIndexPath(forItem:0, inSection:0)])