![](/img/trans.png)
[英]How do I save a high score number in Xcode SpriteKit even if I exit the app and reopen it?
[英]How to reopen the window of app, Xcode
我正在阅读“ OS X的可可编程”(The Big Neard Ranch Guid),我制作了一个最简单的应用程序,用于使用窗口控制器和该控制器的xib文件测试空的Windows应用程序。 我已经按照本书编写了所有必要的代码,但是在构建应用程序并关闭应用程序窗口后,我无法重新打开应用程序窗口。 怎么了 ? 下面的代码。 (我删除了MainMenu.xib中的窗口,并相应地更改了AppDelegate;并且未选中“启动时可见”框))。 这本书说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
}
}
在我的控制器课上
import Cocoa
class Control: NSWindowController
{
override var windowNibName: String?
{
return "Control"
}
}
在“文件的所有者”标识中表示控制控制器,并且窗口已连接至窗口出口。
您必须添加以下应用程序委托方法。
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.