具有共享窗口的基于可可文档的应用程序?

发布于 2024-09-30 09:45:37 字数 124 浏览 3 评论 0原文

我正在开发一个基于文档的应用程序。每个文档都有三个窗口(因此有三个窗口控制器)。我想对其进行设置,以便在不同的打开文档之间共享三个窗口中的两个(根据需要交换视图)。这可能吗?谁能指出我正确的方向(文档或示例)?

谢谢!

I'm developing a document based app. Each document has three windows (and hence three window controllers). I'd like to set it up so that two of the three windows are shared between different open documents (swapping views as needed). Is this possible? Can anyone point me in the right direction (documentation or examples)?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

dawn曙光 2024-10-07 09:45:37

在这种情况下,这些共享窗口控制器不应该由任何文档拥有(因为每个文档都有自己的一对“共享”窗口),而应该是独立的,可能由应用程序委托或文档控制器拥有。您可能还想制作窗户面板,就像检查员一样。

您需要让每个控制器跟踪哪个窗口是主窗口,并在主窗口更改时相应地更新其窗口,因为新的主窗口可能有不同的文档。

几乎任何有关如何制作检查器窗口的教程都会对您有所帮助。

In that case, these shared window controllers should not be owned by any document (since each document would then have its own pair of the “shared” windows), but should be independent, probably owned by the app delegate or the document controller. You may also want to make the windows panels, as an Inspector would be.

You'll want to have each controller track which window is main, and update its window accordingly when the main window changes, because the new main window may have a different document.

Pretty much any tutorial on how to make an Inspector window will help you here.

寄居者 2024-10-07 09:45:37

看起来您需要重写 NSDocument 子类中的 -makeWindowControllers 来创建所需的控制器,在 NSDocument 子类上调用 -addWindowController:添加您的共享窗口控制器。

我还没有这样做,但这些是我会考虑的方法。

来自 Apple 的 NSDocument 类参考:

makeWindowControllers

子类可以重写此方法来为文档创建初始窗口控制器。

- (void)makeWindowControllers

讨论

基类实现使用 windowNibName 创建一个 NSWindowController 对象,如果 windowNibName 返回名称,则将文档作为文件的所有者。如果您重写此方法来创建自己的窗口控制器,请务必在创建后使用 addWindowController: 将它们添加到文档中。

此方法由 NSDocumentController open... 方法调用,但在某些情况下您可能希望直接调用它。

It looks like you need to override -makeWindowControllers in your NSDocument subclass to create the controllers you want, invoking -addWindowController: on the NSDocument subclass to add your shared window controllers.

I haven't yet had to do this, but those are the methods I'd be looking at.

From Apple's NSDocument class reference:

makeWindowControllers

Subclasses may override this method to create the initial window controller(s) for the document.

- (void)makeWindowControllers

Discussion

The base class implementation creates an NSWindowController object with windowNibName and with the document as the file’s owner if windowNibName returns a name. If you override this method to create your own window controllers, be sure to use addWindowController: to add them to the document after creating them.

This method is called by the NSDocumentController open... methods, but you might want to call it directly in some circumstances.

╭ゆ眷念 2024-10-07 09:45:37

这是可能的,但这需要您付出大量的工作。总之,您需要执行以下操作:

  • 覆盖窗口控制器中的 setDocument: 并维护它与每个文档的关联。
  • 确保每个窗口控制器 (NSWindowController) 在窗口关闭之前将其自身与文档解除关联。对于可能处理窗口内视图的每个视图控制器也是如此。
  • 子类化文档控制器 (NSDocumentController) 并负责文档关闭,以确保在关闭任何文档之前将多文档窗口与文档分离。 NSDocumentController 是一个单例,因此您需要在 MainMenu.xib 文件中添加一个实例来替换默认实例。

您可以在此处阅读我的如何添加对多文档窗口控制器的支持的分步指南< /a>.

It is possible, but it'll take a non-trivial amount of work from your side. In summary here's what you need to do:

  • Override setDocument: in the window controller and maintain the associations that it has to each document.
  • Make sure that each window controller (NSWindowController) disassociates itself from the document before the window is closed. The same goes for each view controllers that may be handling views inside the window.
  • Subclass the document controller (NSDocumentController) and take care of document closing to make sure that multi-document windows are detached from documents before any of the documents are closed. NSDocumentController is a singleton and thus you need to add an instance in your MainMenu.xib file to replace the default one.

You can read my step-by-step guide how to add support for multi-document window controllers here.

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