简体   繁体   English

iPhone Interface Builder和代理

[英]iPhone Interface Builder and Delegates

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

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. 如果我创建另一个.xib文件,并为它创建一个委托,并将该文件的所有者设置为我刚刚创建的新委托,我不会在...对象(?)列表中看到“NewDelegateFile”。厦门国际银行。

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. 这对我来说没有意义,我认为这是我为什么不能快速赶上iPhone开发的一个重要原因。

Does anyone care to take the time to explain that little peculiarity to me? 有没有人愿意花时间向我解释这个小小的特点?

File's Owner is not a real object in the xib file. 文件的所有者不是xib文件中的真实对象。 It is a proxy object. 它是一个代理对象。 It represents the object that will become the xib's owner when it is loaded. 它表示在加载时将成为xib所有者的对象。 First Responder and App Delegate are proxies also. First Responder和App Delegate也是代理。 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. 您可以使用此代理对象将文件 - >保存菜单之类的内容连接到任何给定时间负责处理它的对象。

The App Delegate is an actual object. App Delegate是一个实际的对象。 It springs to live when the xib is loaded. 当xib加载时,它会弹出。 As you can see in Interface Builder, it is connected to the delegate outlet of file's owner. 正如您在Interface Builder中看到的那样,它连接到文件所有者的委托出口。 The Application loads the MainWindow.xib, it is therefor the file's owner. 应用程序加载MainWindow.xib,它就是文件的所有者。

Other xib file are usually loaded through a delegate object. 其他xib文件通常通过委托对象加载。 That delegate object is the file's owner. 该委托对象是文件的所有者。 But the delegate itself is instantiated from code. 但代理本身是从代码中实例化的。 It is not loaded from the xib. 它不是从xib加载的。 That's why it is not shown in Interface Builder. 这就是它在Interface Builder中没有显示的原因。

xib files contain actual serialized objects. xib文件包含实际的序列化对象。 File's Owner and First Responder are exceptions. 文件的所有者和第一响应者是例外。 They represent some other, already existing object. 它们代表了一些其他已存在的对象。

File's Owner (often a UIViewDelgate in non MainWindow.xib files) is the chicken. 文件的所有者(通常是非MainWindow.xib文件中的UIViewDelgate)是鸡。 The xib is the egg. xib是鸡蛋。 The chicken itself is not contained in the egg. 鸡蛋本身不含鸡蛋。

A bit long. 有点长。 Hope it helps. 希望能帮助到你。

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

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