這是我所有的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
我很肯定他們是一樣的:)我關注這個 –