V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
axdz
V2EX  ›  Swift

Swift collectionview 插入数据崩溃的问题

  •  1
     
  •   axdz · 2020-01-08 13:39:14 +08:00 · 2170 次点击
    这是一个创建于 1781 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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,用了第二个高票答案,但没有用。 第一个高票答案没看懂,大神指点一下,不知道有没有其它方法

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2772 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 09:42 · PVG 17:42 · LAX 01:42 · JFK 04:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.