2015-10-27 41 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)])