我想通過單擊主窗口中的按鈕來快速顯示/隱藏窗口。起始窗口顯示窗口,但終端窗口不關閉窗口。我的appdelegate代碼給出:通過在Swift中單擊按鈕顯示/隱藏窗口
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
var settingsController: SettingsController?
@IBAction func inSettings(sender: NSObject?)
{
settingsController = SettingsController(windowNibName: "SettingsController")
window.beginSheet(settingsController!.window!, completionHandler: nil)
}
@IBAction func outSettings(sender: NSObject?)
{
window.endSheet(settingsController!.window!)
}
}
SettingsController:
import Cocoa
class SettingsController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
}
襯頁是不是爲我工作 – Devan
@Devan「不工作」是無益的。有沒有錯誤,如果是的話,哪一個?它什麼都不做?請詳細說明。 – Moritz
澄清了'orderOut'的使用... – Aderstedt