-1

At first I thought the nib only produced the sub view (the destination object instance that had an owner, namely, the view controller).

Now from my understanding (or misunderstanding) the view controller (the owner) is actually contained in the same nib file when an outlet is being used.

Does this mean that both the view controller AND the view are 'produced by' or instantiated by the nib file?

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user7024499
  • 951
  • 1
  • 10
  • 24

1 Answers1

1

A nib consists of whatever it consists of, meaning whatever you put there. It sounds from your question, though, as if you might be asking about how storyboards work, since they use nibs that you do not directly interact with.

In a storyboard, each scene consists of two nibs: one containing the view controller, the other containing the view controller's view (and its subviews and everything else).

In a xib file representing a view controller's view, the view controller itself is merely a proxy object (the File's Owner); it is not produced from the nib, but rather already exists at nib-loading time (that is why it can act as the file's owner). That in fact is also how the second nib file in a storyboard scene works.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • From what I just read, I believe it may be the case that if you have an already existing object that you want to be the future owner object, when you create an outlet connection, that already existing object instance will now 'magically' become apart of the nib file. Therefore, even though the owner instance doesn't NEED the nib to exist, it still becomes part of the nib, and when the nib is loaded, you now have two separate instances, one being the original owner object but now it has a new property that refers to the instance that it owns. Correct? – user7024499 Nov 30 '16 at 17:12
  • There is no magic and it does not become part of the nib file. Did you read the section in my book about the owner and proxy? I explain outlets here with a beautiful diagram: http://www.apeth.com/iOSBook/ch07.html#_outlet_connections – matt Nov 30 '16 at 17:33
  • Thanks Matt, this diagram is a bit different from the one I viewed I will give this one a look over. Much appreciated! – user7024499 Nov 30 '16 at 17:57
  • Okay so now from my understanding, when the nib is loaded, the proxy owner object in the nib connects to the actual owner instance, being that the owner instance has loaded the nib with the 'owner' argument set to 'self'. From there, the String value of the outlet is used to further assign the newly created instance generated from the nib load, to the corresponding named reference variable in the owner class. Thanks. – user7024499 Nov 30 '16 at 18:10