更新!我创建了一个经过消毒处理的测试程序,说明了问题。
您可以在这里查看我所做的事情的PDF,并下载项目的.zip文件更新2!请查看下面Conceited Code的评论线程,以了解更多关于此问题的信息。
更新:添加赏金,我正在寻找对我的示例实际存在的问题进行解释、修复和比当前“LoadNib_Controller”更适合我的目的的设计的说明(请参见Conceited Code的评论讨论)
我收到一个运行时错误消息:" [<
My_WindowLoader 0x100228ba0>
valueForUndefinedKey:]: this class is not key value coding-compliant for the key managedObjectContext."
My_WindowLoader引用了My_AppDelegate(我已经调试过,并且肯定正确设置)。它还有一些My_WindowController *'s.. 它们是My_WindowController:NSWindowController。它们被用来为加载nib时提供一个属性(managedObjectContext),这样我就可以设置我的核心数据绑定。它们看起来像是..
.h:
@interface My_WindowController : NSWindowController {
NSManagedObjectContext *managedObjectContext;
}
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
.m
@synthesize managedObjectContext;
我的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,并且已经有了最新的加载。