这是我所有的NSFetchedResultsControllerDelegate
:EXC_BAD_ACCESS:在line tableView.endUpdates()
//MARK: - NSFetchedResultsControllerDelegate
func controllerWillChangeContent(controller: NSFetchedResultsController) {
self.tableView.beginUpdates()
}
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
switch type {
case .Insert:
if let newIndexPath = newIndexPath {
tableView.insertRowsAtIndexPaths([reversedIndexPathForIndexPath(newIndexPath)], withRowAnimation: .Fade)
}
case .Delete:
if let indexPath = indexPath {
tableView.deleteRowsAtIndexPaths([reversedIndexPathForIndexPath(indexPath)], withRowAnimation: .Fade)
}
case .Update:
if let indexPath = indexPath {
if let cell = tableView.cellForRowAtIndexPath(reversedIndexPathForIndexPath(indexPath)) as? WLCommentTableViewCell {
updateCell(cell, withIndexPath: indexPath)
}
}
case .Move:
if let indexPath = indexPath, let newIndexPath = newIndexPath {
tableView.deleteRowsAtIndexPaths([reversedIndexPathForIndexPath(indexPath)], withRowAnimation: .Fade)
tableView.insertRowsAtIndexPaths([reversedIndexPathForIndexPath(newIndexPath)], withRowAnimation: .Fade)
}
}
}
func controllerDidChangeContent(controller: NSFetchedResultsController) {
tableView.endUpdates() //Thread 1: EXC_BAD_ACCESS (code=1, address=0x20)
updateView()
if shouldScrollTableToBottom {
scrollTableViewToBottom()
}
}
有时我的应用程序在与tableView.endUpdates()
行崩溃。为什么?
你确定你的数据源的数量,我的意思是更新前和更新后的行数是相同的。请检查一下,这可能会有所帮助。 – Sabby
我很肯定他们是一样的:)我关注这个 –