collectionview 插入数据崩溃

2020-01-08 14:07:43 +08:00
 axdz

collectionview 插入数据崩溃了,代码如下

let selectIndex = self.photoData.seletedAssetArray.index(of: self.previewPhotoArray[currentIndex]) if selectIndex != nil{ self.rightButton.asyncSetImage(UIImage.zyCreateImageWithView(view: ZYPhotoNavigationViewController.zyGetSelectNuberView(index: "(selectIndex! + 1)")), for: .selected) }

    if selectIndex != nil{
        if self.rightButton.isSelected == false {
            let indexPath = IndexPath.init(row: selectIndex!, section: 0)
            self.photoData.seletedAssetArray.remove(at: self.photoData.seletedAssetArray.index(of: self.previewPhotoArray[currentIndex])!)
            thumbnailCollectionView.deleteItems(at: [indexPath])
        }else{
            let indexPath = IndexPath.init(row: selectIndex!, section: 0)
            thumbnailCollectionView.numberOfItems(inSection: 0)
            thumbnailCollectionView.insertItems(at: [indexPath])
            thumbnailCollectionView.reloadItems(at: [indexPath])
            thumbnailCollectionViewCellToggeleSelect(indexPath: indexPath)
        }
    }

报错信息: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

网上查了一下,https://stackoverflow.com/questions/19199985/invalid-update-invalid-number-of-items-on-uicollectionview,用了第二个高票答案,但没有用。 第一个高票答案没看懂,大神指点一下,不知道有没有其它方法

2708 次点击
所在节点   Objective-C
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/636134

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX