Xcode/ios: Core Data Prepare for segue error with topViewController

Xcode/ios: Core Data Prepare for segue error with topViewController

我正在尝试在 Tuts plus 和 NSFetchResultsController 上关注关于核心数据的优秀 tutorial。但是,为 segue 方法做准备会引发错误。这是代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"addToDoViewController"]) {
        // Obtain Reference to View Controller
        UINavigationController *nc = (UINavigationController *)[segue destinationViewController];
        AddToDoVCViewController *vc = (AddToDoVCViewController *)[nc topViewController];

        // Configure View Controller
        [vc setManagedObjectContext:self.managedObjectContext];
    }
}

具体来说,UINavigation 行没问题。然而,以下以 AddTo... 开头的行给出了 5 个红色错误:

Missing '[' at start of send expression
Expected ']'
Use of undeclared identifier 'vc'
Expected expression
Use of undeclared identifier 'AddTodoVCViewController'

Configure View Controller 后的下一行给出红色错误:

Use of undeclared identifier 'vc'

检查了文件的拼写等。此时我几乎卡住了。非常感谢任何建议。

你的代码没问题。检查不平衡 []{},并尝试使用
执行清理 CmdAltShiftK.