关闭文档窗口并打开一个新窗口,而不关闭文档

发布于 2024-08-15 12:40:21 字数 846 浏览 7 评论 0原文

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

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

[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];

我在解决问题的失败尝试中添加了保留和释放消息。)

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

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

My app is document-based, but the “document” consists of two folders, not one file. The document's initial window contains a couple of file pickers and a button; the action closes that window and opens a new one showing the results of the operation between the two folder hierarchies. (The two windows are significantly different in size; keeping both views in a tabless tabview and switching with that would be non-trivial.)

Here's the code from my action method that closes the file-pickers window and opens the results window:

[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];

(I added the retain and release messages in a failed attempt to solve the problem.)

My problem is that the document gets released and deallocated after this action method finishes, despite my telling the initial window controller not to close the document. (That was another failed attempt to solve the problem.)

So, how can I replace the first window with another, for the same document, without the document dying off?

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

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

发布评论

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

评论(1

十二 2024-08-22 12:40:21

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

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

这表明窗口控制器正在关闭其文档。我不知道为什么,因为我告诉它不要在上一行中这样做。

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

I finally solved this by switching the removeWindowController: and close messages:

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

This would suggest that the window controller was closing its document on close. I don't know why, because I'd told it not to on the immediately-previous line.

I also removed the explicit retain and release messages. The problem did not return.

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