2016-05-04 76 views
1

我正在使用故事板和swift。 現在我正試圖打開一個新的NSWindow,它被打包在一個xib文件中。 (我創建了一個包含NSWindow的新xib文件)從xib使用故事板和快速打開NSWindow

我已將下面的代碼添加到我的項目中,但它不打開任何窗口。

let controller = NSWindowController(windowNibName: "xibFile") 
controller.showWindow(self) 

我知道我在做什麼錯了,因爲

print(controller.window?.title) 

也不會給我從廈門國際銀行文件的正確的窗口標題。

希望任何人都可以提示我做錯了什麼。謝謝!

+0

請問您的廈門國際銀行窗口有自定義類或只是NSWindowController? 你在哪裏觸發'controller.showWindow(self)'?那是在AppDelegate裏面嗎? – Jacky

回答

2

在你的第二個筆尖:

class SecondNibController: NSWindowController { 
    override var windowNibName: String? { 
     return "SecondNib" // no extension .xib here 
    } 
} 

記住的window出口SecondNibConntroller連接到你的窗口。

在您的主要故事板:

class ViewController: NSViewController { 
    let secondNibController = SecondNibController() 

    @IBAction func openSecondWindow(sender : AnyObject) { 
     secondNibController.showWindow(nil) 
    } 
}