EXC_BAD_ACCESS 当我试图删除 UITableView 部分时 [英] EXC_BAD_ACCESS when I'm trying to delete a UITableView sections
本文介绍了EXC_BAD_ACCESS 当我试图删除 UITableView 部分时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
// - Update the data source
self.order.persons.removeAtIndex(index)
// - Disable the user interaction
self.tableView.userInteractionEnabled = false
// - Delete the needed section from the table view
let sectionIndexSet = NSIndexSet(index: self.order.persons.count - 1)
self.tableView.beginUpdates()
self.tableView.deleteSections(sectionIndexSet, withRowAnimation: .Automatic)
self.tableView.endUpdates()
// - Update the table view with a delay to update all the indexes
NSTimer.scheduledTimerWithTimeInterval(0.3, handler: {
self.tableView.userInteractionEnabled = true
self.tableView.reloadData()
})
所以问题:
案例 1:当表视图的可见区域上有其他部分时,不仅是我要删除的部分,而且一切正常.
CASE 1: When on the visible zone of table view are another sections, not only the one that I want to delete, all works great.
案例 2:当表视图的可见区域上只有我要删除的部分时,调试器停在该行:
CASE 2: When on the visible zone of table view is ONLY the section that I want to delete, the debugger stop at the line:
self.tableView.endUpdates()
并给出错误:
线程 1:EXC_BAD_ACCESS(代码=1,地址=0x0).
我不明白为什么案例 1 效果很好,但案例 2 不行.有关信息,我使用可重复使用的单元格.
I don't understand why case 1 is working great, but case 2 not. For information, I use reusable cells.
推荐答案
您正在从源和 tableView 中删除不同的数据
You are removing different data from source and in tableView
问题
// - Delete the needed section from the table view
let sectionIndexSet = NSIndexSet(index: self.order.persons.count - 1)
修复应该是
// - Delete the needed section from the table view
let sectionIndexSet = NSIndexSet(index: index)
这篇关于EXC_BAD_ACCESS 当我试图删除 UITableView 部分时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文