mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Crash on cell deletion/insertion in sectioned list #76
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @avshiyanov on GitHub (Sep 8, 2016).
I have many sections on the list, for example 5, first one have only one element in section, when I do transation.delete(obj) App crashes. The same occurs if section does not exist and I do insert
Crash
CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of sections. The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted). with userInfo (null)
Here is deletion logic:
CoreStore.beginAsynchronous { (transaction) -> Void in
transaction.delete(task)
transaction.commit()
}
In data source I have:
// MARK: ListObserver
@avshiyanov commented on GitHub (Sep 8, 2016):
CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of sections. The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted). with userInfo (null)
@JohnEstropia commented on GitHub (Sep 8, 2016):
@avshiyanov I'm guessing this is because of
moveRowAtIndexPathandreloadRowsAtIndexPaths, which do not really work well withNSFetchResultsController's event logic.You can check that UITableViews work well with the CoreStoreDemo app. You'll see the main difference here:
For updates, query the cell instance from the tableView and update it directly. For moves, delete the row first then re-insert.
@avshiyanov commented on GitHub (Sep 8, 2016):
@JohnEstropia When I comment moveRowAtIndexPath and reloadRowsAtIndexPaths I have the same issue, problem still persists on insertion/deletion for Sections only
@avshiyanov commented on GitHub (Sep 8, 2016):
monitorSectionedList: func buildListMonitorByTime(withPredicate predicate: NSPredicate?) ->
ListMonitor {
return CoreStore.monitorSectionedList(
From(TaskRecord),
SectionBy("dateName"),
OrderBy(.Descending("createdAt")),
Tweak { (fetchRequest) -> Void in
let sortDescriptor = NSSortDescriptor(key: "createdAt", ascending: false)
fetchRequest.sortDescriptors = [sortDescriptor]
})
}
@avshiyanov commented on GitHub (Sep 8, 2016):
@JohnEstropia Found mistake on my side, forgot implement ListSectionObserver, without it didInsertSection, didDeleteSection does not call for me. Closed
@JohnEstropia commented on GitHub (Sep 8, 2016):
Glad you worked it out :)