gpt4 book ai didi

cocoa - NSWindowController 的文档在什么条件下可以改变?

转载 作者:行者123 更新时间:2023-12-03 17:01:02 26 4
gpt4 key购买 nike

我的应用程序观察其 NSWindowControllerdocument 属性,并在设置时执行一些 UI 设置。一旦设置完毕,就很难因更改而重建 UI(出于内部原因)。

一旦 NSWindowController 将其 document 属性设置为打开的文档,在什么条件下系统会将该属性更改为新的NSDocument 实例(即文档是否会被换出)?我从未观察到这种情况发生,但我可以想象版本或 iCloud 同步等功能会导致窗口 Controller 的文档被交换为新文档。但是,有关 NSWindowController 生命周期的文档似乎没有涉及这个问题。

最佳答案

一旦设定就不会改变。 NSWindowController 通过 addWindowController 方法获取其文档。每个新的/打开的文档都会创建它自己的 windowController。文档实例不会随 iCloud 或 revertChanges 更改。如何将文档与其 View 同步(重绘)取决于您。

/* Create the user interface for this document, but don't show it yet. 
The default implementation of this method invokes [self windowNibName],
creates a new window controller using the resulting nib name (if it is not nil),
specifying this document as the nib file's owner, and then invokes [self addWindowController:theNewWindowController] to attach it. You can override
this method to use a custom subclass of NSWindowController or to create more
than one window controller right away. NSDocumentController invokes this method
when creating or opening new documents.
*/


// e.g. override
- (void)makeWindowControllers
{
if ([[self windowControllers] count] == 0) {
MainWindowController *controller = [[MainWindowController alloc] init];
[self addWindowController:controller];
}
}

关于cocoa - NSWindowController 的文档在什么条件下可以改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54694268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com