对于密钥managedObjectContext,此类不符合键值编码
更新!我已经创建了一个清理过的测试程序来说明问题。
在这里,您可以查看我已完成的PDF文件,并下载该项目的.zip文件
UPDATE2!请参阅下面的自负代码的评论主题,以了解有关此问题的更多信息。
更新:添加赏金,我正在寻找一个解释我的示例实际上有什么问题,修复了什么,以及哪个设计比当前的“LoadNib_Controller”更适合我的目的(参见自负的代码评论讨论)
我收到运行时错误消息
“[
<
My_WindowLoader0x100228ba0>
valueForUndefinedKey:]:此类与密钥managedObjectContext不符合密钥值编码。”
My_WindowLoader有一个对My_AppDelegate的引用(我已经调试过并且肯定已正确设置)。它还有一些My_WindowController *的..它们是My_WindowController:NSWindowController。它们被使用,以便我可以向Windows提供一个属性(managedObjectContext),当我加载nib时,它会加载,以便我可以设置我的Core Data绑定。他们看着像是..
.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并且最新加载。
没有找到相关结果
已邀请:
4 个回复
嘘伪
我应该这样做
注意与initWithWindowNibName的区别:vs initWithWindowNibName:owner: 此外,放置此代码的正确位置在AppDelegate中,它是App控制器,这种类型的逻辑在那里。
念炯
缉康怪
降女陷费券