What is a standard way to add a ViewController in a Mac OS X Cocoa app? (or is it required?)

后端 未结 2 2043
情书的邮戳
情书的邮戳 2021-02-06 02:23

I\'d like to start a Cocoa app with a ViewController just like the iOS \"Single View App\" template, but there is no such template (is there a public / open source

2条回答
  •  我寻月下人不归
    2021-02-06 03:07

    The "Controller" in OS X with respect to managing NSViews is the NSWindowController. Though Drummer says that NSViewController isn't very useful, I must disagree - it is useful for splitting up your NSWindowController once it gets too large, and has clear logical divisions in terms of views.

    You could have one NSWindowController, and once it gets complicated enough, the NSWindowController could delegate tasks corresponding to specific views to subclasses of NSViewController, and in that respect it is very useful.

    In the default templates (if I remember correctly) the AppDelegate takes the role of the window controller, though it isn't technically one. In more complex applications it is a good idea to instantiate a window controller instead.

    As long as you don't mix up the controller and view anything can be used. The View should be relegated to just display and basic input handling.

提交回复
热议问题