RCB*_*RCB 8 xcode interface-builder ios
IB中对象和外部对象有什么区别?
我什么时候应该使用?
添加到另一个答案:您可以使用"外部对象"来跨多个xib访问公共对象.你也可以用其他方式做到这一点,但这很方便.
例如,如果您对多个xib上的按钮点击执行了"大"操作,并且您有许多此类操作(另外如果您执行此操作的数据相同),而不是调用addTarget:action...,则可以创建此类的代理对象并将其连接到按钮.
您可以使用以下代码将代理对象连接到xib:
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];
Run Code Online (Sandbox Code Playgroud)
对象是实际嵌入笔尖中的东西。
外部对象是加载笔尖的代码承诺在加载时提供的对象(我相信通过将键映射到外部对象的字典)。
大多数人从不使用除文件所有者(已为您提供)之外的任何外部对象。几乎可以肯定,您只想要对象。
| 归档时间: |
|
| 查看次数: |
2205 次 |
| 最近记录: |