Reputation: 71
From what I understand, MainMenu.xib contains XML that is used to create the main menu for an application. My question is, how is this file loaded, read, and used to create the main menu? Can anyone help me to understand the inner workings of the code that translates MainMenu.xib into the actual main menu seen in the UI?
Here is my understanding of the process so far.
This is the part I am confused about. How exactly is the UINib object used to create the Main Menu?
Upvotes: 1
Views: 143
Reputation: 64002
Imagine this the other way around: you have a live view hierarchy in memory, in your running application. Now you want to allow the program to be terminated while saving the state of the UI. How would you do that? You would somehow write all the important properties of the live views to disk; some kind of serialization and archiving process.
That's all a nib is: it's an archive of a bunch of objects that happen to be views. (It encodes the "base" state of the views, of course, before any user interaction.) A xib, as you correctly noted, is an XML rendering of that archive, which makes it cooperate better with version control.
If you take a look at the XML of a xib in Xcode, you'll see that it consists of entries like this:
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="161" id="KGk-i7-Jjw" customClass="LeakInfoStepsCell" customModule="LookoutEmailLeakAlert" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="170"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
...
Just a listing of various properties on the view and the values they should have when the nib is unarchived. So when you load a UINib, it's reading those properties and creating view objects, just as you might do manually in code, or as you would do for your own object via NSCoding
.
Upvotes: 2