I've fixed it! Or rather, NSFetchedResultsController fixed it. I've implemented
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
in my view controller to deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:
. My delete method is now just
NSManagedObjectContext *context = [NSManagedObjectContext MR_defaultContext];
[object MR_deleteInContext:context];
[context MR_saveToPersistentStoreAndWait];
(thanks for the advice about MR_contextForCurrentThread).
Here's loadData:
NSManagedObjectContext *c = [NSManagedObjectContext MR_defaultContext];
NSPredicate *textParentFilter = [NSPredicate predicateWithFormat:@"parent == %@", self.parent];
self.notes = [Note MR_fetchAllSortedBy:@"text" ascending:YES withPredicate:textParentFilter groupBy:nil delegate:self inContext:c];
NSPredicate *folderParentFilter = [NSPredicate predicateWithFormat:@"parentFolder == %@", self.parent];
self.folders = [Folder MR_fetchAllSortedBy:@"title" ascending:YES withPredicate:folderParentFilter groupBy:nil delegate:self inContext:c];
And - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section:
if ([self.notes.sections count] + [self.folders.sections count] > 0) {
id <NSFetchedResultsSectionInfo> notesSectionInfo = [self.notes.sections objectAtIndex:section];
id <NSFetchedResultsSectionInfo> foldersSectionInfo = [self.folders.sections objectAtIndex:section];
return [notesSectionInfo numberOfObjects] + [foldersSectionInfo numberOfObjects];
} else
return 0;