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

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

问题描述

我是Cocoa新手,我不明白.nib档案的档案拥有者的概念。

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 文件来描述窗口的外观。

  • Consider a file myNibFile.nib file that describes how looks a window.

现在,我想将一个实际的窗口连接到.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文件是 myWindow ?是不是多余?

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

我想这意味着我没有真正理解文件的所有者。它是什么 ?为什么.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 !

推荐答案


  • 文件所有者是加载nib的对象。也就是说。因此,如果您要在加载对象之后从对象访问nib中的任何对象,请为文件所有者设置一个插座。

所以你创建了一个有许多按钮,子视图等的花哨视图。如果要在从加载对象(通常是视图或窗口控制器)加载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 . Its that simple .

这就是为什么默认情况下所有的视图控制器或窗口控制器都作为文件所有者,并有一个出口到主窗口或视图对象在nib文件coz duh如果你控制的东西,你一定需要有一个插座,以便你可以发送消息到它。

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

它的被调用文件所有者并给出特殊地方的原因是,与nib中的其他对象不同,文件所有者在nib外部,而不是它的一部分。它仅在加载笔尖时可用。因此,文件所有者是实际对象的替身或代理,稍后将加载nib。
希望你明白了。如果你问,我将澄清任何要点。

The reason its called file owner and given a special place is that unlike the other objects in the nib the file owner is external to the nib and is not part of it . 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天全站免登陆