【发布时间】:2015-01-28 11:13:29
【问题描述】:
我一直在尝试了解 OS X 的 StoryBoards —— 具体来说,我正在尝试使用 Core Data 编写基于文档的应用程序。
我不知道如何让 StoryBoard 中的各种视图控制器访问 NSPersistentDocument 的 managedObjectController。
在 StoryBoards 之前,如果您使用 Core Data 制作基于文档的应用程序,您会得到一个 XIB 文件,其中包含一个窗口,其所有者是文档。 Document 有一个窗口控制器数组,但该 XIB 的所有者是 Document。你可以添加一个NSArrayController,将它的Managed Object Context绑定到所有者的Managed Object Context,一切都很好。
如果您使用 StoryBoards 创建项目,则顶层窗口由 NSWindowController 拥有。 NSPersistentDocument 在哪里?它被创建了,但我看不到在哪里或为什么。
此外,在您使用模板获得的初始故事板中,该窗口没有传入箭头,表示它是入口点。如果您删除窗口控制器并添加一个新的,它有一个箭头。现在,您将拥有两个窗口控制器——一个由情节提要制作,一个由 Document 制作,后者在其 makeWindowControllers 方法中创建它
- (void)makeWindowControllers {
// Override to return the Storyboard file name of the document.
[self addWindowController:[[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"Document Window Controller"]];
}
这是一个错误吗?显然有些东西我不明白。
【问题讨论】:
-
我也有同样的问题。你知道怎么做吗?
标签: core-data storyboard xcode6