我可以使用Interface Builder在多个nibs之间注入依赖吗? [英] Can I use Interface Builder to inject dependencies across multiple nibs?

查看:99
本文介绍了我可以使用Interface Builder在多个nibs之间注入依赖吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于从外部为我的对象提供依赖。 Interface Builder是一个帮助这样做的工具,但我不能使它与多个nibs一起工作。一旦我将主要的nib断开成更多的文件,我不能再在不同的nibs中的对象之间建立连接。使用文件所有者没有什么帮助,因为它只允许我将一个单一的对象传递到一个nib。

I am used to supplying the dependencies for my objects from the outside. Interface Builder is a tool that helps doing this, but I can’t make it work with multiple nibs. As soon as I break the main nib into more files, I can no longer make connections between objects in different nibs. Using File Owner does not help very much, since it only allows me to pass one single object into a nib.

示例:

>

这里A和B是一些较高级别的对象,C和D是某种较低级别的服务。只要所有的对象都在一个大的笔尖(第一张图片)内,一切都很好。但是当我将笔尖拆分成A和B时,我将它们连接到C和D(显然我不想创建C和D的两个实例,我想让A和B都在同一个C和D而不使用单例。)

Here A and B are some higher-level objects and C and D some kind of lower-level services. As long as all objects are inside one big nib (first picture), everything is fine. But when I split the nib to separate A and B, I have trouble connecting them to C and D. (Obviously I do not want to create two instances of C and D, I want both A and B talking to the same C and D without using a singleton.)

是否可以在Interface Builder中执行此操作?如何?

Is it possible to do this in Interface Builder? How?

推荐答案

.nib中的对象对应于您的视图层,对吗?当取消存档时,它们由您选择的控制器所拥有,它们在您的服务和您的视图之间进行中介。

The Objects in your .nib correspond to your view layer, right? When unarchived they are owned by your chosen controller, which mediates between your services and your view.

有任何种类的低级服务真的是非常规的,任何类型的依赖都存档在.nib文件中。

It would be really unconventional to have any kind of lower-level services, or any kind of dependencies at all archived in your .nib file.

这篇关于我可以使用Interface Builder在多个nibs之间注入依赖吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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