2015-09-08 88 views
0

我試圖讓NSWindow在點擊該窗口的相應按鈕時出現(關於 - > aboutWindow,首選項 - > preferencesWindow)。當我點擊按鈕打開窗口時,它們會閃爍然後消失。我看了一兩個關於如何修復它的文章,但是它比較模糊,並且在Objective-C中解釋過,而不是Swift。我想我知道問題是什麼(在@IBAction內創建的實例,一旦動作完成就擺脫實例),但我不知道如何解決它。NSWindow閃爍

所有的代碼是在上https://github.com/madebybright/Nimble/tree/windows

爲固定的解釋,將不勝感激。

回答

0

你只需要將你的控制器的聲明移出你的方法。嘗試是這樣的:

let aboutController = AboutController(windowNibName: "About") 
let preferencesController = PreferencesController(windowNibName: "Preferences") 

func showAbout(sender: AnyObject) { 
    println("showing about window") 
    aboutController.showWindow(aboutController.aboutWindow) 
} 

func showPreferences(sender: AnyObject) { 
    println("showing preferences window") 
    preferencesController.showWindow(preferencesController.preferencesWindow) 
} 
+0

我發誓我已經嘗試過,它沒有工作! :P謝謝你的答案:) – josh

+0

@josh歡迎您 –