2010-07-10 26 views
0

我的應用程序中有一個按鈕,當您單擊它時會打開一個新的NSWindow。但是,如果你繼續點擊它將會打開另一個NSWindow。我怎樣才能限制可見窗口的數量?允許具體數量的NSWindow副本可見

回答

2

禁用按鈕。如果您有一個創建新窗口的按鈕,那麼它應該創建一個新窗口。如果你不想讓用戶創建一個新窗口,不要讓他們點擊按鈕。

編輯如果您正在處理類似於偏好窗口的內容,那麼您應該使用NSWindowController子類來控制該窗口。點擊按鈕應該基本上(preferencesWindowController是一個伊娃):

- (void) showPreferences:(id)sender { 
    if (preferencesWindowController == nil) { 
    preferencesWindowController = [[PreferencesWindowController alloc] init]; 
    } 
    [preferencesWindowController showWindow:sender]; 
} 
+0

它更像是一個偏好窗口。 – 2010-07-10 18:16:05

+0

@Matt S.編輯答案 – 2010-07-10 18:38:40