iPhone Interface Builder和代理 [英] iPhone Interface Builder and Delegates

查看:88
本文介绍了iPhone Interface Builder和代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我制作一个示例应用程序(即,从标签栏应用程序或其他东西开始)时,在我的MainWindow.xib文件中,我看到列出了5个项目 - 文件所有者,第一响应者,应用程序代表,窗口和选项卡条形码控制器。

When I make a sample app (ie, start out with a tab bar application or something), in my MainWindow.xib file, I see 5 items listed -- File's Owner, First Responder, App Delegate, Window, and Tab Bar Controller.

如果我创建另一个.xib文件,并为其创建委托,并将该文件的所有者设置为我刚刚创建的新代理,我不会在.xib的...对象(?)列表中看到NewDelegateFile。

If I make another .xib file, and make a delegate for it, and set that File's Owner to my new delegate that I just made, I do NOT see "NewDelegateFile" in the list of...objects(?) for that .xib.

这对我来说没有意义,我认为是一个巨大的为什么我没有尽快赶上iPhone开发的部分原因。

This doesn't make sense to me, and I think is a huge part of why I'm not catching on all that quickly to iPhone development.

是否有人愿意花时间向我解释这个小小的特点?

Does anyone care to take the time to explain that little peculiarity to me?

推荐答案

文件的所有者不是xib文件中的真实对象。它是一个代理对象。它表示在加载时将成为xib所有者的对象。 First Responder和App Delegate也是代理。第一响应者是当前在响应者链顶部的对象。当应用程序的状态发生变化时,另一个对象可能是第一个响应者。您可以使用此代理对象将文件 - >保存菜单之类的内容连接到任何给定时间负责处理它的对象。

File's Owner is not a real object in the xib file. It is a proxy object. It represents the object that will become the xib's owner when it is loaded. First Responder and App Delegate are proxies also. The first responder is the object currently on top of the responder chain. When the state of the application changes, another object might be the first responder. You use this proxy object to connect things like the File->Save menu to whatever object is responsible handling it at any given time.

App Delegate是一个实际对象。当xib加载时,它会弹出。正如您在Interface Builder中看到的那样,它连接到文件所有者的委托出口。应用程序加载MainWindow.xib,它就是文件的所有者。

The App Delegate is an actual object. It springs to live when the xib is loaded. As you can see in Interface Builder, it is connected to the delegate outlet of file's owner. The Application loads the MainWindow.xib, it is therefor the file's owner.

其他xib文件通常通过委托对象加载。该委托对象是文件的所有者。但委托本身是从代码中实例化的。它不是从xib加载的。这就是它在Interface Builder中没有显示的原因。

Other xib file are usually loaded through a delegate object. That delegate object is the file's owner. But the delegate itself is instantiated from code. It is not loaded from the xib. That's why it is not shown in Interface Builder.

xib文件包含实际的序列化对象。文件的所有者和第一响应者是例外。它们代表了一些其他已存在的对象。

xib files contain actual serialized objects. File's Owner and First Responder are exceptions. They represent some other, already existing object.

文件的所有者(通常是非MainWindow.xib文件中的UIViewDelgate)是鸡。 xib是鸡蛋。鸡蛋本身不包含在鸡蛋中。

File's Owner (often a UIViewDelgate in non MainWindow.xib files) is the chicken. The xib is the egg. The chicken itself is not contained in the egg.

有点长。希望它有所帮助。

A bit long. Hope it helps.

这篇关于iPhone Interface Builder和代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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