将数据传递到特定的打开的 NSDocument?
我在这个问题上遇到了很多麻烦。我需要有一个 NSViewController
和一个 NSView
将整数传递给特定文档。我真的希望它将数据传递到由键窗口表示的文档(我希望这是有意义的),但我所做的方式将数据传递到所有打开的文档。
我正在使用来自 Xcode 模板的基于文档的应用程序(Cocoa 应用程序,选中了“基于文档的应用程序”框。有什么办法可以做到这一点吗?
我没有发布我的代码,因为它真的太尴尬了。基本上,我有NSViewController 中的“getter”方法,但我仍然没有想到传回数据的好方法,我最终得到了数百行代码,这些代码应该使文档拉取数据。与另一个数据返回“getter”方法,但他们没有做任何事情
?
I have been having lots of trouble with this one. I need to have an NSViewController
and an NSView
pass integer's to a specific document. I really want it to pass the data to the document represented by the key window (I hope that makes sense), but the way I am doing passes the data to all of the open documents.
I am using a document based application, from the Xcode template (Cocoa application with the "Document based application" box checked. Is there any way to do this?
I did not post my code because it really is too embarrassing. Basically, I have a "getter" method in the NSViewController
, but I still have not thought of a good way to pass the data back. I ended up with hundreds of lines of code that are supposed to make the document pull the data back with another "getter" method, but they don't do anything.
Is there any documentation on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关键窗口后面可能没有文档,它只是首先接收事件的窗口,我想您可能需要的是
-[NSApplication mainWindow]
,您可以从中获取窗口控制器从该文档中,您也可以观察NSWindowDidBecomeMainNotification
来跟踪哪个窗口现在是主窗口,或者您可以使用方法-[NSAppliation OrderedDocuments]
来获取前面 文档。我个人喜欢 NSNotification,但可能有些树脂您更喜欢其他方法之一。The key window may not have a document behind it, it is just the window that will receive events first, I think what you may be after is
-[NSApplication mainWindow]
which you can get the window controller for and from that the document, alternatively you could observer theNSWindowDidBecomeMainNotification
to keep track of which window is now main or you could use the method-[NSAppliation orderedDocuments]
to get the front document. Personnaly I like theNSNotification
but there may be resins you prefer one of the other methods.