[英]How to reopen the window of app, Xcode
I am reading "Cocoa programming for OS X" (The Big Neard Ranch Guid) and I have made a simplest application to test an empty windows app with a window controller and xib file for this controller. 我正在阅读“ OS X的可可编程”(The Big Neard Ranch Guid),我制作了一个最简单的应用程序,用于使用窗口控制器和该控制器的xib文件测试空的Windows应用程序。 I have wrote all necessary code according to the book but after building the app and closing the window of app I cannot reopen the window of the app.
我已经按照本书编写了所有必要的代码,但是在构建应用程序并关闭应用程序窗口后,我无法重新打开应用程序窗口。 What is wrong ?
怎么了 ? Below the code.
下面的代码。 (I deleted window in MainMenu.xib and accordingly changed AppDelegate; and Visible at Launch box is unchecked) ).
(我删除了MainMenu.xib中的窗口,并相应地更改了AppDelegate;并且未选中“启动时可见”框))。 The book says that showWindow(_:) will reopen the window, but I don't see this !
这本书说showWindow(_ :)将重新打开窗口,但是我看不到!
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var control: Control?
func applicationDidFinishLaunching(aNotification: NSNotification) {
//Create a window controller object
let control = Control()
//Put the window of the window controler om the screen
control.showWindow(self)
//Set the propertity to point to window controler
self.control = control
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}
in my controller class 在我的控制器课上
import Cocoa
class Control: NSWindowController
{
override var windowNibName: String?
{
return "Control"
}
}
In File's Owner identity is for Control controller and window has been connected to window outlet. 在“文件的所有者”标识中表示控制控制器,并且窗口已连接至窗口出口。
You have to add the following application delegate method. 您必须添加以下应用程序委托方法。
func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if flag {
control.window.orderFront(self)
} else {
control.window.makeKeyAndOrderFront(self)
}
return true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.