为什么Mac AppDelegate中没有NSWindow像iOS AppDelegate中一样

时间:2018-07-26 09:14:35

标签: macos

我在iOS开发方面有经验,但在Mac方面没有。我尝试遵循一些旧的Mac教程,但是由于该教程是讲故事板之前的时代而被震惊。

我尝试访问根视图控制器以注入一些要呈现的数据,但是当我打开AppDelegate时,没有像iOS AppDelegate中那样引用NSWindow。

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application

    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
    }
}

我可以使用NSApplication.shared.mainWindow?.windowController?.contentViewController as! ViewController 之类的东西来访问它,但是不知道这样做是否正确。

这里有2个问题

  1. 正确的方法是什么?
  2. 这是什么原因,为什么这里没有窗口实例。

0 个答案:

没有答案
相关问题