NSWindowController Vs的NSViewController之间的区别(Differ

2019-06-25 12:36发布

我从iOS的背景到来,开始学习可可。 在iOS上,除非我们对多目标iPadiPhone ,我们通常有一个窗口和使用管理屏幕UIViewControllers 。 当每一个新的屏幕将大部分时间都将映射到一个UIViewController

但是在可可这似乎是围绕其中一个新的屏幕/窗口由管理otherway NSWindow和它的子组件是由管理NSViewController 。 所以,如果我有多个窗口的应用程序,我应该有独立的NSWindowController每个窗口。

这是正确的做法还是我有误解?

Answer 1:

With iPhone SDK and Leopard SDK, they introduced view controllers, or NSViewController and UIViewController. As their names suggest what they do is to manage views

The view controllers are for managing views. Current trend in UI design is Single Window, Multiple View. What it means is that there is one Window and inside of it, different group of views designed for different purpose can be swapped in and out. So, the View Controllers handles these for programmers for well-established pattern. Currently view controllers are very important for iPhone and iPod touch programming, because the platform is based on Single-Window and Multiple View model. However, it doesn’t seem to me that using view controller is very popular for Mac. how about the window controller like NSWindowController? Its counterpart, UIWindowController doesn’t exist for the iPhone and iPod touch environment, because there is only one window for those environment. Unlike view controllers, the NSWindowController is for document based programs. Well, document based program can use multiple window. So, it is reasonable to think that NSWindowController is for document based programs as Apple’s document says.



Answer 2:

我也来自iOS和开始编码Mac应用程序前一阵子,从苹果公司的文件大多是学习。

我的印象是,在桌面上,你几乎不必NSViewController S(一个大的例外是有标签和多个视图的窗口,像GarageBand的欢迎屏幕)。

大多数时候,你有一个NSWindowController每个窗口。 先学习之间的关系NSWindowNSWindowController (和NSDocument ,如果你正在一个基于文档的应用程序)。

一旦你说对了,开始尝试NSViewController


更新:看来,既然为Mac引入故事板的应用程式太多,苹果公司预计,大部分观点表示逻辑应该从旧的迁移NSWindowController到新NSViewController ,更加符合iOS应用程序是如何构成的。 我不是很懂行的确切位置画线,或者什么样的代码应该留在窗口控制器(或是否仍需要在所有子类)。



文章来源: Difference between NSWindowController Vs NSViewController