我正在构建一个有桌子的应用,并且我试图删除行。首次弹出此错误时,我认为它源自我的视图控制器。我查看了StackOverflow,我发现了与我相似的问题,但没有一个解决方案有效。这是代码:
override func tableView(_ tableView: UITableView,
commit editingStyle: UITableViewCellEditingStyle,
forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
let monsterDude = monsterSections[indexPath.section].monsters[indexPath.row]
verifyDelete(monsterDude.name, {
(action) -> Void in
self.growler.removeMonster(monsterDude)
self.tableView.deleteRows(at: [indexPath],
with: .automatic)
})
}
}
我尝试了很多不同的东西 - 从使用reloadData
进行测试来重写我的numberOfSections
方法 - 所以现在我认为它必须是我的removeMonster方法本身的问题(实际上删除了密钥和我用来存储我所有怪物的字典中的价值。这是班级:
func removeMonster(_ name: String, _ monsterType: MonsterType, _ strength: Strength) {
let monsterMan = Monster(name, monsterType, strength)
removeMonster(monsterMan)
}
func removeMonster(_ monsterMan: Monster) {
monsters.removeValue(forKey: monsterMan.strength)
}
这是我宣布我的字典的方式:
var monsters = Dictionary<Strength, [Monster]>()
以下是错误消息:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.21.8/UITableView.m:2011
2017-11-15 05:04:37.065738-0500 Project1[65062:17116869] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
如果您有任何明显的错误,请告诉我们!如有必要,我很乐意提供更多信息。我只想删除表格中的内容。谢谢!!