【发布时间】:2016-11-11 19:53:35
【问题描述】:
我已经看到了很多关于这个主题的主题,但我仍然有错误......
这是我在 tableview 委托方法中的代码(当用户滑动并单击单元格上的删除按钮时调用):
self.tableView.beginUpdates()
if self.data[sectionType]!.isEmpty {
self.data.removeValue(forKey: sectionType)
}
self.tableView.deleteRows(at: [indexPath], with: .fade)
self.tableView.endUpdates()
我已经实现了这样的 numberOfSections 委托方法:
func numberOfSections(in tableView: UITableView) -> Int {
return data.count
}
这是我得到的错误:
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 内部错误:无法生成具有旧节数:1 和新节数:0 的新节图”
如果我将 deleteRows(in tableView) 方法替换为 reloadData()...
我检查了断点,当错误发生时我输入了 if 条件。所以数据被更新了(removeValue() 调用后的 0 元素),我调用了 deleteRows 方法。
感谢您的帮助。
【问题讨论】:
-
你使用 numberOfRowsInSection 方法了吗?
标签: ios swift uitableview