问题
I have this code:
// - 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()
})
So the problem:
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.
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()
and gives the errors :
Thread 1: EXC_BAD_ACCESS (code=1, address=0x0).
I don't understand why case 1 is working great, but case 2 not. For information, I use reusable cells.
回答1:
You are removing different data from source and in tableView
ISSUE
// - Delete the needed section from the table view
let sectionIndexSet = NSIndexSet(index: self.order.persons.count - 1)
FIX It should be
// - Delete the needed section from the table view
let sectionIndexSet = NSIndexSet(index: index)
来源:https://stackoverflow.com/questions/38328537/exc-bad-access-when-im-trying-to-delete-a-uitableview-sections