【发布时间】:2015-09-30 19:18:27
【问题描述】:
我正在阅读“用于 OS X 的 Cocoa 编程”(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"
}
}
在文件的所有者身份中,控制控制器和窗口已连接到窗口插座。
【问题讨论】: