问题
What is the difference between Object and External Object in the IB?
When should I use each?
回答1:
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.
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.
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];
回答2:
An Object is something that's actually embedded in the nib.
An External Object is one that the code that loads the nib promises to provide at load time (I believe via a dictionary that maps keys to external objects).
Most people never use any External Object besides File's Owner (which is already provided for you). You almost certainly just want Objects.
来源:https://stackoverflow.com/questions/15143606/object-vs-external-object-in-xcode-interface-builder