加载 NIB 并重新建立连接

发布于 2024-10-30 19:18:23 字数 570 浏览 2 评论 0原文

实例化对象后,nib 加载代码如何建立与出口的连接?

苹果文档说:

一旦所有对象都从存档中实例化并初始化,笔尖加载代码就会尝试重新建立每个对象的插座和相应的目标对象之间的连接。如果您的自定义对象有出口,NSNIb 对象会尝试重新建立您在 Interface Builder 中创建的任何连接。它首先尝试使用对象自己的方法建立连接。对于每个需要连接的插座,NSNib 对象会在您的对象中查找 setOutletName: 形式的方法。如果该方法存在,则 NSNib 对象会调用它,并将目标对象作为参数传递。 ...

但是它如何确定目标对象

例如我有一个对象

@interface Foo: NSObject
{
IBOutlet NSButton *redButton;
}

...

@end

和 redButton 通过 IB 与窗口上的按钮连接。笔尖加载代码将如何建立连接?

nib文件中是否有“连接数据”?

How does nib-loading code establish connections to outlets after instantiating objects?

Apple documentation says:

Once all objects have been instantiated and initialized from the archive, the nib loading code attempts to reestablish the connections between each object’s outlets and the corresponding target objects. If your custom objects have outlets, an NSNib object attempts to reestablish any connections you created in Interface Builder. It starts by trying to establish the connections using your object’s own methods first. For each outlet that needs a connection, the NSNib object looks for a method of the form setOutletName: in your object. If that method exists, the NSNib object calls it, passing the target object as a parameter. ...

But how does it determines the target object?

For example I have an object

@interface Foo: NSObject
{
IBOutlet NSButton *redButton;
}

...

@end

and the redButton connected with the button on the window through IB. How will nib-loading code establish the connection?

Is there any "connection data" in the nib file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖心男生 2024-11-06 19:18:23

是的,NIB 文件当然必须存储这些连接。如果您在文本编辑器中打开 XIB 文件,您会发现每个插座连接都有这样的片段:

<object class="IBConnectionRecord">
    <object class="IBOutletConnection" key="connection">
        <string key="label">launchAtLoginCheckBox</string>
        <reference key="source" ref="1001"/>
        <reference key="destination" ref="951818764"/>
    </object>
    <int key="connectionID">72</int>
</object>

因此,Apple 使用私有类 IBConnectionRecordIBOutletConnection 的实例对连接进行建模。

Yes, of course the NIB file has to store these connections. If you open a XIB file in a text editor, you will find snippets like this for every outlet connection:

<object class="IBConnectionRecord">
    <object class="IBOutletConnection" key="connection">
        <string key="label">launchAtLoginCheckBox</string>
        <reference key="source" ref="1001"/>
        <reference key="destination" ref="951818764"/>
    </object>
    <int key="connectionID">72</int>
</object>

So it looks like Apple uses instances of the private classes IBConnectionRecord and IBOutletConnection to model the connections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文