When the last row moves in the UITableView section with the main data & # 8594; NSRangeException

Hey. Moving rows between partitions in Core Data supported by UITableView works very well after I implemented the check for 'userDrivenChange' in 'controllerDidChangeContent:', as mentioned in the apple docs. But only when moving the last line of a section to another section, I get an NSRangeException . Obviously, the problem occurs when partitions become empty. How can I handle this best way?

+3
source share
1 answer

Have you implemented the method -controller:didChangeSection:atIndex:forChangeType:? If not, it might look something like this:

-(void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {     
    switch(type) {          
        case NSFetchedResultsChangeInsert:
            [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}
0
source

Source: https://habr.com/ru/post/1734482/


All Articles