开发者

When last row in section of UITableView with Core Data is moved -> NSRangeException

开发者 https://www.devze.com 2022-12-21 19:34 出处:网络
Hi: Moving rows between sections in Core Data backed UITableView works quite fine after I\'ve implemented a \'userDrivenChange\' check in \'controllerDidChangeContent:\', as mentioned in the apple doc

Hi: Moving rows between sections in Core Data backed UITableView works quite fine after I've implemented a 'userDrivenChange' check in 'controllerDidChangeContent:', as mentioned in the apple docs. But only when moving the last row of a section to another section I get a NSRangeException. There is ob开发者_如何学编程viously a problem when sections get empty. How could I handle that the best way?


Have you implemented the -controller:didChangeSection:atIndex:forChangeType: method? If not, that may 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

精彩评论

暂无评论...
验证码 换一张
取 消