在Mac OS X Cocoa应用程序中添加ViewController的标准方法是什么? (或者是否需要?) [英] What is a standard way to add a ViewController in a Mac OS X Cocoa app? (or is it required?)

查看:329
本文介绍了在Mac OS X Cocoa应用程序中添加ViewController的标准方法是什么? (或者是否需要?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ViewController 开始一个Cocoa应用,就像iOS的单一视图应用模板,但没有这样的模板/开源一个可以使用?)

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 one that can be used?)

对于Cocoa应用程序来说,我们并不需要一个,因为 NSView 可以做一切吗?我们可以把所有的事件处理放在我们的自定义NSView类中。可能是iOS需要它更多,因为旋转由ViewController处理,旋转通常是必需的?但是如果我们使用MVC,那么最好总是使用一个ViewController,如果是这样,是否有一个标准的方法,一个模板来做呢?

Is it true that for Cocoa apps, we don't really need one, because an NSView can do everything already? We can just put all the event handling in our custom NSView class. Could it be that iOS requires it a lot more because rotation is handled by the ViewController and rotation is usually required? But if we use MVC, then it might be better to always use a ViewController, and if so, is there a standard way, a template, to do it?

推荐答案

OS X中关于管理NSView的控制器是 NSWindowController 。虽然Drummer说, NSViewController 不是非常有用,我必须不同意 - 它是有用的拆分你的 NSWindowController 一次

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.

你可以有一个 NSWindowController ,并且一旦它变得足够复杂, NSWindowController 可以将对应于特定视图的任务委托给 NSViewController 的子类,在这方面它是非常有用的。

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.

在默认模板中(如果我没记错的话) AppDelegate 扮演窗口控制器的角色,在技​​术上不是一个。在更复杂的应用程序中,最好实例化一个窗口控制器。

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.

这篇关于在Mac OS X Cocoa应用程序中添加ViewController的标准方法是什么? (或者是否需要?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆