【发布时间】:2011-03-17 18:19:52
【问题描述】:
更新!我创建了一个说明问题的净化测试程序。
Here you can view a PDF of exactly what I've done, and download a .zip of the project更新2!请参阅下面的 Conceited Code 的评论线程以了解有关此问题的更多信息。
更新:增加了赏金,我正在寻找对我的示例实际错误的解释,修复它的方法,以及比当前的“LoadNib_Controller”更适合我的目的的设计(请参阅自负代码评论讨论)
我收到运行时错误消息
" [<My_WindowLoader 0x100228ba0>valueForUndefinedKey:]: 这个类与键 managedObjectContext 的键值编码不兼容。"
My_WindowLoader 有一个对 My_AppDelegate 的引用(我已经调试过并且肯定设置正确)。它还有一些 My_WindowController *'s .. 它们是 My_WindowController : NSWindowController。使用它们是为了向 Windows 提供一个属性(managedObjectContext),当我加载 nib 时加载它,这样我就可以设置我的核心数据绑定。他们看起来像..
.h:
@interface My_WindowController : NSWindowController {
NSManagedObjectContext *managedObjectContext;
}
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
.m
@synthesize managedObjectContext;
My_WindowLoader 以下列方式加载 nib:
Window1_WindowController = [[My_ WindowController alloc] initWithWindowNibName:@"Window1" owner:self];
// The following line I have debugged and it does in fact go to my app delegate, wherein it instantiates a MOC (since this is the first place in the code that it's used..), and returns it, and it appears to also be setting it via the property in My_WindowController
[Window1_WindowController setManagedObjectContext:[AppDelegate managedObjectContext]];
// The following is where I get my problem, this does load my window but in my gdb window I see the runtime error message that I list at the top of this post
NSWindow *window1Pointer = [Window1_WindowController window];
为了得到上述运行时错误,在我的 Window1.nib 中,我有数组控制器,它们使用模型键路径“managedObjectContext”将它们的托管对象上下文绑定到“文件所有者”。文件的所有者是类型 My_WindowController
显然出了点问题,但我已经使用调试器以及使用常识逐步完成了它,这一切似乎都应该起作用。我看到大多数“这个类不是 kvc ..”错误源于 IBOutlet/IB 等中的错误命名,但我在这里对所有这些进行了三次检查,并确保我完全退出并重新启动了 Xcode/IB 并加载了最新的。
【问题讨论】:
标签: objective-c cocoa