XCode Interface Builder中的对象与外部对象 [英] Object vs. External Object in XCode Interface Builder

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

问题描述

IB中的对象和外部对象有什么区别?

我什么时候应该使用?

What is the difference between Object and External Object in the IB?
When should I use each?

推荐答案

添加到另一个答案:
您可以使用外部对象来访问公共对象多个xib。你也可以用其他方式做到这一点,但这很方便。

Adding on to the other answer: You could use an 'External Object' to access a common object across multiple xib's. You could do this in other ways too, but this would be convenient.

例如,如果您对多个xib上的按钮点击执行大操作,并且您有许多此类操作(另外如果它是相同的话)您正在执行此操作的数据),而不是调用 addTarget:action ... ,您可以创建此类的代理对象并将其连接到按钮。

Like for example, if you have a 'big' action to be performed for button clicks over multiple xib's and if you have many such actions (and additionally if it's the same data you are performing this action on), instead of calling addTarget:action... , you could create the proxy object of this class and wire it up to the buttons.

您可以使用以下代码将代理对象连接到xib:

You can connect the proxy object to your xib using the following code:

 id *proxy = <someObject>; //The object you want to wire up
//In the below line of code use the same key as the identifier you give for the proxy object in the Interface Builder
 UINib *nib = [UINib nibWithNibName:@"ViewController" bundle:Nil];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:proxyObject,@"proxy", nil];
NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:dict,UINibExternalObjects, nil];
NSArray  *nibArray = [nib instantiateWithOwner:self options:dict2];
self.view = [nibArray objectAtIndex:0];

这篇关于XCode Interface Builder中的对象与外部对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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