【发布时间】:2016-06-10 02:36:58
【问题描述】:
我有 2 个这样的集合视图:
第一个是相册的收藏视图,第二个是每个相册中照片的收藏视图。
数据来自服务器。我想将一些照片从专辑 A 移动到专辑 B。
我试过这样:
if response != nil {
// Update UI Move photo from AlbumA to AlbumB
// Get all images from albumA
var sourceImages: [UIImage] = []
for i in 0..<self.checkSelectedImages[self.selectedAlbumIndex].count {
if self.checkSelectedImages[self.selectedAlbumIndex][i] == false {
let cell = self.imageCollectionView.cellForItemAtIndexPath(NSIndexPath(forRow: i, inSection: 0)) as! ODIProfileMovePhotoImageCell
let sourceImage = cell.imageView.image
self.imageCollectionView.deleteItemsAtIndexPaths([NSIndexPath(forRow: i, inSection: 0)])
sourceImages.append(sourceImage!)
self.imageCollectionView.reloadData()
}
}
// Send those above images to AlBumB
for i in 0..<sourceImages.count {
self.imageCollectionView.insertItemsAtIndexPaths([NSIndexPath(forRow: i, inSection: 0)])
}
self.imageCollectionView.reloadData()
}
和 numberOfItemsInSection:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.albumCollectionView {
return listData.count + 1
}
else if collectionView == self.imageCollectionView {
if listData.count > 0 {
if selectedAlbumIndex > 0 {
return listData[selectedAlbumIndex - 1].photos.count
} else {
return thumbnailImagesFromPhotoLibrary.count
}
}
}
return thumbnailImagesFromPhotoLibrary.count
}
但它在这一行崩溃:
self.imageCollectionView.deleteItemsAtIndexPaths(indexPaths!)
上面写着:
由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'无效更新:无效 第 0 节中的项目数。包含在第 0 节中的项目数 更新后的现有节 (14) 必须等于 更新前该部分中包含的项目 (14),加号或减号 从该部分插入或删除的项目数(0 插入, 1 已删除)加上或减去移入或移出的项目数 该部分(0 移入,0 移出)。'
如何解决这个问题?
【问题讨论】: