更新(1)后集合视图中包含的节数必须等于更新前的集合视图中包含的节数(1),加上或减去插入或删除的节数(1)插入,0删除)。
答案 0 :(得分:1)
您是否将numberOfSections
基于某种型号?发生了什么事情是你在某个地方的表视图中插入一个部分,重新加载表格视图数据,然后应用程序崩溃,因为numberOfSections
不等于The number of sections contained in the collection view after the update
。
如果没有看到您的代码,就很难确定问题所在,但我会查看您插入某个部分的位置并找出如何相应地更新numberOfSections
。
一个基本的例子就是拥有一个像
这样的存储变量 var sectionsCount = 1
当您插入一个部分时,您可以执行sectionsCount = sectionsCount + 1
,重新加载您的tableView数据,并拥有:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sectionsCount.count
}
请记住,在重新加载数据之前,您始终必须更新您的表格视图。