文件的所有者是什么(在界面构建器中)? [英] What is the File's Owner (in Interface builder)?

查看:21
本文介绍了文件的所有者是什么(在界面构建器中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Cocoa 的新手,我不明白 .nib 文件的 File's Owner 的概念.

I am new to Cocoa and I don't understand the concept of File's Owner of a .nib file.

这是我看待事物的方式:

Here is the way I would see things :

  • 考虑一个描述窗口外观的文件 myNibFile.nib 文件.

现在,我想将一个实际窗口连接到这个 .nib 文件.因此,我创建了一个 myWindow 类,它是 NSWindowController 的子类.并且,为了实现这个连接,我改变了 init 方法,如下所示:

Now, I want to connect an actual window to this .nib file. So, I create a class myWindow, which is a subclass of NSWindowController. And, to do this connection, I change the init method like this:

     -(id)init
     {
         [super initWithWindowNibName:@"myNibFile"];
         return self;
     }

所以,我明白当我创建一个 myWindow 的实例时,系统"会去查看 .nib 文件并创建足够的对象.

So, I understand that when I create an instance of myWindow, the "system" will go and look at the .nib file and create the adequate object.

所以,我的问题是:

  • 为什么我必须指定我的 .nib 文件的 File's OwnermyWindow ?不是多余的吗?

  • why do I have to specify that the File's Owner of my .nib file is myWindow ? Isn't it redundant ?

我想这意味着我并没有真正理解 File's Owner 是什么.它是什么 ?为什么 .nib 文件必须属于某个东西?它不能在我的应用程序"中的某处",当需要时,系统"会去那里使用它吗?

I guess it means I didn't really understood what the File's Owner. What is it ? Why does the .nib file have to belong to something ? Can't it be "somewhere" in my "application" and when it is needed, the "system" goes there and use it ?

感谢您帮助我更清楚地了解这些新概念!

Thanks for helping me to see more clearly in these new concepts !

推荐答案

需要记住的两点:

  • 文件所有者是加载笔尖的对象,即接收消息 loadNibNamed:initWithNibName: 的对象.
  • 如果您想在加载后访问 nib 中的任何对象,您可以在文件所有者中设置一个出口.

所以你创建了一个带有很多按钮、子视图等的奇特视图.如果您想在从加载对象(通常是视图或窗口控制器)加载笔尖后随时修改这些视图/对象中的任何一个,请将这些对象的出口设置为文件所有者.就这么简单.

So you created a fancy view with lots of buttons, subviews etc . If you want to modify any of these views / objects any time after loading the nib FROM the loading object (usually a view or window controller) you set outlets for these objects to the file owner. It's that simple.

这就是为什么默认情况下所有视图控制器或窗口控制器都充当文件所有者的原因,并且在 nib 文件中也有一个到主窗口或视图对象的出口:因为废话,如果你控制某些东西,你会肯定需要有一个出口,以便您可以向它发送消息.

This is the reason why by default all View Controllers or Window Controllers act as file owners, and also have an outlet to the main window or view object in the nib file: because duh, if you're controlling something you'll definitely need to have an outlet to it so that you can send messages to it.

它之所以被称为文件所有者并被赋予一个特殊的位置,是因为与笔尖中的其他对象不同,文件所有者是笔尖的外部对象,而不是笔尖的一部分.事实上,它只有在加载笔尖时才可用.因此,文件所有者是实际对象的替身或代理,稍后将加载笔尖.

The reason it's called file owner and given a special place, is because unlike the other objects in the nib, the file owner is external to the nib and is not part of it. In fact, it only becomes available when the nib is loaded. So the file owner is a stand-in or proxy for the actual object which will later load the nib.

希望你已经明白了.如果你问,我会澄清任何一点.

Hope you've understood. I'll clarify any of the points if you ask.

这篇关于文件的所有者是什么(在界面构建器中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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