Mac应用程序故事板 - 访问文档在NSViewController [英] Mac App Storyboard - Access Document in NSViewController

查看:322
本文介绍了Mac应用程序故事板 - 访问文档在NSViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在一个基于文档的基于故事板的Cocoa应用程序(Objective C)中与NSDocument打斗。
任何人都可以告诉我我如何访问NSViewController子类中的文档?

I am currently fighting with NSDocument in a document based Storyboard based Cocoa Application (Objective C). Can anybody tell me how i can access the document in the NSViewController subclass?

我试图通过以下方式访问它 - 但是文档是null :

I've tried to access it the following way - but the document is null:

[self.view.window.windowController document];

感谢您的帮助!

关于
Martin

Best regards Martin

推荐答案

我只是自己摔跤。我开始使用标准的Yosemite模板,并试图在 -viewDidLoad [self.view.window.windowController document] >。在这一点上, self.view.window nil ,所以没有办法到达 document

I was just wrestling with this myself. I started with the standard Yosemite template and was trying to use [self.view.window.windowController document] in -viewDidLoad. At that point, self.view.window is nil, so there's no way to get to the document.

诀窍是等待 -viewWillAppear 。到调用时, self.view.window 已填充,文档可用。

The trick is to wait until -viewWillAppear. By the time it is called, self.view.window is populated and the document is available.

序列: -makeWindowControllers 使用storyboard的调用 -self addWindowController: instantiateControllerWithIdentifier:结果。 -addWindowController:在返回之前触发对VC的 -viewDidLoad 的调用。然后,最后,调用 -viewWillAppear (并且文档可用)。

Sequence: -makeWindowControllers invokes -self addWindowController: with the storyboard's -instantiateControllerWithIdentifier: result. -addWindowController: triggers a call to the VC's -viewDidLoad before returning. Then, finally, -viewWillAppear is called (and the document is available).

这篇关于Mac应用程序故事板 - 访问文档在NSViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆