ios - 删除 UITableview 崩溃应用程序中的部分
问题描述
我有一个 UITableView,我想删除部分和行。我正在尝试删除其中包含行的整个部分。以下是让我感到困惑的案例。
- 当我尝试从上到下或从下到上删除部分时,所有部分都会被删除而不会出错
- 当我尝试随机删除部分时,即首先我删除顶部的第一部分,然后当我尝试删除第 4 或第 8 或最后一个部分时,应用程序会自行崩溃
崩溃日志
致命错误:索引超出范围
这是我的做法:
func onHeaderSwippedRight(ClickedSection: IndexPath) {
dataSource.remove(at: ClickedSection.section)
// use the UITableView to animate the removal of this row
tableView.beginUpdates()
tableView.deleteSections(IndexSet.init(integer : ClickedSection.section), with: .automatic)
tableView.endUpdates()
}
我传递给此函数onHeaderSwippedRight(ClickedSection: IndexPath)的索引路径由委托方法传递。Bcz 在我的课堂上,我在设置我的部分数据时传递它
我的一个原始猜测是,在删除部分 tableview 之后必须更新部分的索引,因为当我从数据源中删除数据时,如果部分自己更新,它一定不会让 Index out of bound 问题
请帮助并告诉我我做错了什么
更新;
public class ListModel : Object {
var Id : String = ""
var UserId : Int64 = 0
var Name : String? = ""
var Items : [ListDetailServiceModel]? = []}
这是我的模型,我有这样的列表
let dataSource :[ListModel] = []
解决方案
推荐阅读
- c# - 我可以将 JSON 数组反序列化为类的属性吗?
- python - Python中的静态方法和类方法有什么区别?
- java - 如何使用所有可能的对组合进行for循环(+- 1,+- 2)
- php - 如何将数组多个数组键和值从控制器传递到 Codeigniter 中的视图?
- consul - 使用 consul-template 向 nginx.conf 渲染 2000+ 服务
- python-3.x - Easygui 无法正常工作,repl.it 上的 Python 3.8.1
- c++ - 'max' 作为一个变量是如何工作的,即使它通常是一个函数?
- node.js - 在回调函数nodejs中传递属性
- java - 从 unix 平台上的多个 JVM 实例调用 Cipher.getInstance() 时速度很慢
- ios - 应用程序不支持排行榜 - iMessage 应用程序