我在 UITableView 生成的每个单元格上实现了一个复制、编辑和删除按钮(每个单元格都是由用户需求创建的)。复制和编辑按钮以相同的方式编码并且工作得很好。但是,每次按下删除按钮时,都会收到错误消息“线程 1:信号 SIGBART”。不知道如何修复。任何帮助,将不胜感激。
一些有用的信息: - 每个单元格是一个部分,每个部分在 tableview 中都有一行 - 在 cellview 的代码中适当地连接按钮,并适当地委派在表格视图中使用。
我是 swift 的初学者,所以请耐心等待。下面的代码来自我的 UITableViewController。我尝试从节索引和它引用的对象中删除单元格。然后,我尝试重新加载 UITable 视图上的数据。但是,单击删除按钮的那一刻,我只是收到错误消息。
func hashtagCellDidTapDelete(_ cell: HashtagCell) {
if tableView.indexPath(for: cell) != nil {
let indexPath = tableView.indexPath(for: cell)
tableView.deleteSections([(indexPath?.section)!], with: .fade)
hashtagSource.hashtags.remove(at: (indexPath?.section)!)
tableView.reloadData()
}
}
首先从数据源中删除项目,然后更新 UI。
并使用 Optional Binding 来解开可选项indexPath
以避免丑陋的括号、问号和感叹号。
并且永远不会reloadData()
在之后调用insert/deleteRows/Sections
。
func hashtagCellDidTapDelete(_ cell: HashtagCell) {
if let indexPath = tableView.indexPath(for: cell) {
hashtagSource.hashtags.remove(at: indexPath.section)
tableView.deleteSections([indexPath.section], with: .fade)
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句