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

后端 未结 2 2007
情书的邮戳
情书的邮戳 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 02:52

    On OS X NSViewController isn't as often used as UIViewController on iOS. One of the reasons is that it's not really useful and lacks a lot of the nice features of UIViewController. There are only a couple of situations where you really have to use them, like when using an NSPopover.

    There are several ways to structure your OS X code. One of them is using NSWindowController. You can think of NSWindowController as the equivalent of UIViewController on iOS.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题