views:

78

answers:

1

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?

A: 

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.

Peter Hosey