将数据传递到特定的打开的 NSDocument?

发布于 2024-11-27 17:38:48 字数 372 浏览 0 评论 0原文

我在这个问题上遇到了很多麻烦。我需要有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻风 2024-12-04 17:38:48

关键窗口后面可能没有文档,它只是首先接收事件的窗口,我想您可能需要的是 -[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 the NSWindowDidBecomeMainNotification 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 the NSNotification but there may be resins you prefer one of the other methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文