简体   繁体   English

NSTabView与NSTabViewController —何时使用控制器?

[英]NSTabView vs NSTabViewController — When to use the controller?

The NSTabViewController was only introduced in OS X v10.10, so NSTabView already provides everything you need for creating a tab view. NSTabViewController仅在OS X v10.10中引入,因此NSTabView已经提供了创建选项卡视图所需的一切。 When would you use a NSTabViewController, and is it only there to be subclassed? 什么时候使用NSTabViewController,并且仅在其中进行子类化?

If you compare iOS & OS X, you will feel OS X is bit deviated from MVC. 如果比较iOS和OS X,您会觉得OS X与MVC有点偏离。 OS X default 'new project' opens with AppDelegate as compared to iOS with 'ViewController'! 与iOS的“ ViewController”相比,OS X的默认“新项目”通过AppDelegate打开!

Now, it seems, Apple decided to make it by adding Controller as well. 现在看来,苹果公司决定也通过添加Controller来做到这一点。 So that the view NSTabView is controlled by NSTabViewController . 因此,视图NSTabViewNSTabViewController控制。

And yes if you design to subclass it and use that should reduce your job. 是的,如果您打算对其进行子类化和使用,那将会减少您的工作。 Same thing is mentioned even in Apple Documentation . 即使在Apple文档中也提到了同样的事情。

I would use NSTabViewController to get rid of a lot of code I used to have to write to have a tab view and transition between those views (most often done in Preference windows in Mac apps). 我将使用NSTabViewController摆脱很多我以前不得不编写的代码,它们具有选项卡视图和这些视图之间的过渡(通常在Mac应用程序的“首选项”窗口中完成)。

You'd obviously have to be 10.10 only, but these days that's a safe bet. 显然,您仅需为10.10,但这几天是安全的选择。

As for subclassing it, judging by the api I'd start without sub-classing it. 至于子类化,从api判断,我将不对其进行子类化。 You can set the style, the transition options (a nice benefit of using it!), and then call addTabViewItem: and let it do it's stuff. 您可以设置样式,过渡选项(使用它的好处!),然后调用addTabViewItem:并使其完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM