删除 NSCollectionView 中的项目会引发错误

问题描述

美好的一天,

我有一个需要大量添加和删除的 NSCollectionView。我有一个函数可以完美地添加到 NSCollectionView 的末尾,并且可以有效地工作,但是我删除 NSCollectionView 中项目的函数有时会起作用,但有时它会在下面引发错误是错误


Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift,line 444
2021-02-19 09:08:34.718073+0100 Kokoca[33243:2652479] Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift,line 444

我保存了一个用户默认值来告诉我用户正在删除哪个部分和项目。我已经这样做了,因为它非常重要,因此用户无法删除第一个项目,但是当我尝试删除其他项目时,它有时会起作用,直到当我继续尝试删除更多项目时它崩溃。我对 collectionViews 不是很熟悉,所以任何帮助将不胜感激。提前致谢。下面是我的代码:

    
    @objc func deleteview() {
        var newSearch = UserDefaults.standard.integer(forKey: "DeletedTab")
        let newSection = UserDefaults.standard.integer(forKey: "DeletedSection")
        if newSearch == 0 {
            return
        }
        else {
            self.theTabList.remove(at: newSearch)
            print(newSearch)
            print(newSection)
            var set: Set<IndexPath> = [IndexPath(item: newSearch,section: newSection)]
            tabCollectionView.deleteItems(at: set)
            theViewList.remove(at: newSearch)
            theViewList[newSearch].removeFromSuperview()
            var defaults = UserDefaults.standard
            var theCurrentTab = tabCollectionView.item(at: IndexPath(item: theTabList.count - 1,section: 0)) as! TabItem
            theCurrentTab.isSelected = true
            print("TheTabList: " + String(theTabList.count))
            print(theTabList)
        }
    }
}

任何想法为什么它有问题?将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...