swift - 从具有多个部分的 tableview 中删除
问题描述
我正在尝试删除UITableView
包含多个部分的行。当有 1 个部分时,我看到的所有教程都会删除一行。
我的数据 [[String]]:
[["Section 0, Item 0", "Section 0, Item 1"], ["Section 1, Item 0"]]
无论我刷哪一行,我都会收到错误消息:
'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
我的删除代码:
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let pulled = UIContextualAction(style: .destructive, title: "Pulled", handler: {(_, _, completionHandler) in
self.pullList.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .fade)
completionHandler(true)
})
return UISwipeActionsConfiguration(actions: [pulled])
}
如果有专门针对此的教程,那就太棒了。我的部分可以有 1-4 行。
解决方案
如果pullList
是[[String]]
你必须删除
self.pullList[indexPath.section].remove(at: indexPath.row)
推荐阅读
- python - 正则表达式匹配,如果不匹配则更改格式
- angularjs - AngularJS 控制器在 ng-Route 期间未正确加载,否则()
- amazon-web-services - aws golang sdk 进行异步创建实例调用
- openlayers - OpenLayers 6 - 添加第二个矢量切片图层会导致基础图层标签消失
- c# - 无法从“对象”转换为“MySql.Data.MySqlClient.MySqlDbType”
- c++ - *--end() 在 C++ 中是什么意思?
- javascript - TS/JS 自启动类
- c# - 带有asp.net网页表单页面代码的扩展方法存在问题
- list - 在列表中的元素之间添加零?
- python - 在 Linux Mint 中使用启动器和基本代码启动 Jupyter Notebook