关闭文档窗口并打开一个新窗口,而不关闭文档
我的应用程序是基于文档的,但“文档”由两个文件夹组成,而不是一个文件。该文档的初始窗口包含几个文件选择器和一个按钮;该操作将关闭该窗口并打开一个新窗口,显示两个文件夹层次结构之间的操作结果。 (这两个窗口的大小显着不同;将两个视图保留在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终通过切换
removeWindowController:
和close
消息解决了这个问题:这表明窗口控制器正在关闭其文档。我不知道为什么,因为我告诉它不要在上一行中这样做。
我还删除了显式的
retain
和release
消息。问题没有再出现。I finally solved this by switching the
removeWindowController:
andclose
messages: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
andrelease
messages. The problem did not return.