2009-12-18 233 views
0

我的應用程序是基於文檔的,但「文件」包括兩個文件夾,而不是一個文件。文檔的初始窗口包含幾個文件選擇器和一個按鈕;該操作將關閉該窗口並打開一個新窗口,顯示兩個文件夾層次結構之間的操作結果。 (這兩個窗口的大小明顯不同;在tabless tabview中保留這兩個視圖並使用該視圖進行切換將是非平凡的。)關閉文檔窗口並打開一個新的,而不關閉文檔

下面是我的操作方法中的代碼,它關閉了文件撿拾器窗口並打開結果窗口:

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

(我加的是保持在一個失敗的嘗試解決問題,釋放等消息。)

我的問題是,該文件被釋放,釋放這個動作方法完成後,儘管我告訴初始窗口控制器不關閉文檔。 (這是一個失敗的嘗試,以解決這個問題。)

所以,我怎麼能與另一個替換第一個窗口中,相同的文檔,無需文檔消亡?

回答

1

我終於解決了這個通過切換removeWindowController:close消息:

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

這表明,窗口控制器收盤時上接近它的文檔。我不知道爲什麼,因爲我已經告訴過它不要在前一條線上。

我也去掉了明確retainrelease消息。問題沒有回來。

相關問題