How does OS X load a storyboard based app, and how does it do window management?

点点圈 提交于 2019-12-03 03:46:08
The Cappy
  1. No. Checking the "Create Document-Based Application" is what made it a document based app. The decision to use Core Data is separate.

  2. The Storyboard you get when you make an OS X Document based app is a bit atypical. Notice that there is no arrow in the storyboard telling you where the entry point it. What happens is "Document" is instantiated. It has a method:

    override func makeWindowControllers() {
        // Returns the Storyboard that contains your Document window.
        let storyboard = NSStoryboard(name: "Main", bundle: nil)!
        let windowController = storyboard.instantiateControllerWithIdentifier("Document Window Controller") as NSWindowController
        self.addWindowController(windowController)
    }
    

It goes looking in the storyboard for a controller with the identifier @"Document Window Controller" (which just so happens is that window controller). Document keeps a collection of windowControllers. so Document instantiates it and adds the windowController to that list.

So Document already has a reference to the window controller in Document.windowControllers

(Can someone tell me WHY the Document gets created though? I can't see what actually triggers its creation)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!