gpt4 book ai didi

cocoa - 关闭文档窗口并打开新窗口,而不关闭文档

转载 作者:行者123 更新时间:2023-12-03 18:06:14 25 4
gpt4 key购买 nike

我的应用程序是基于文档的,但“文档”由两个文件夹组成,而不是一个文件。该文档的初始窗口包含几个文件选择器和一个按钮;该操作将关闭该窗口并打开一个新窗口,显示两个文件夹层次结构之间的操作结果。 (这两个窗口的大小明显不同;将两个 View 保留在 tabless 选项卡 View 中并进行切换将是非常重要的。)

这是我的操作方法中的代码,用于关闭文件选择器窗口并打开结果窗口:

[self retain];
NSArray *existingWindowControllers = [[[self windowControllers] copy] autorelease];
for (NSWindowController *windowController in existingWindowControllers) {
[windowController setShouldCloseDocument:NO];
[windowController close];
[self removeWindowController:windowController];
}
[self addWindowController:[[[NSWindowController alloc] initWithWindowNibName:@"ProjectFoldersDocument" owner:self] autorelease]];
[self showWindows];
[self release];

(我添加了保留和释放消息,但尝试解决该问题失败了。)

我的问题是,尽管我告诉初始窗口 Controller 不要关闭文档,但在此操作方法完成后,文档仍被释放和取消分配。 (这是解决问题的又一次失败尝试。)

那么,对于同一个文档,如何用另一个窗口替换第一个窗口,而不会使文档消失?

最佳答案

我最终通过切换 removeWindowController:close 消息解决了这个问题:

[self removeWindowController:windowController];
[windowController close];

这表明窗口 Controller 正在关闭其文档。我不知道为什么,因为我告诉它不要在前一行。

我还删除了显式的 retainrelease 消息。问题没有再出现。

关于cocoa - 关闭文档窗口并打开新窗口,而不关闭文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1927688/

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