在交换机中未处理枚举值'NSFetchedResultsChangeMove'和NSFetchedResultsChangeUpdate'

Geo*_*sda 4 xcode uitableview ios

我收到此警告:在交换机中未处理枚举值'NSFetchedResultsChangeMove'和NSFetchedResultsChangeUpdate'

有任何想法吗?

- (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;
    }
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView endUpdates];
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

car*_*rso 16

你也可以添加

        default:
        break;
Run Code Online (Sandbox Code Playgroud)

摆脱那些警告.


pba*_*sdf 11

编译器知道NSFetchedResultsChangeType有四个可能的值,但是您的代码只处理其中的两个.如果您确定不会发生其他两个,则可以忽略该警告.但是最安全的做法是包含一些代码来处理这些其他值,无论是什么都没有,或者是NSLog来查看它们是否确实发生.我想补充一下

case NSFetchedResultsChangeMove:
    NSLog(@"A table item was moved");
    break;
case NSFetchedResultsChangeUpdate:
    NSLog(@"A table item was updated");
    break;
Run Code Online (Sandbox Code Playgroud)

进入你的switch语句.编辑:检查了文档后,我发现这两个值不用于Section更改,因此您可以忽略警告或在上面的行中添加null case语句来抑制警告.