**ios:xib file parsing (comparison of Xib and storyboard, a lightweight one heavyweight)

Source: Internet
Author: User
<span id="Label3"></p><p><p>Using Xcode as an iOS project often deals with xib files because the Xib file visually shows the appearance of the runtime view, so it's easy to get started and easy to use, but for kids who never write a view with pure code, Most of them have a partial understanding of xib.</p></p><p><p>What is a xib file?</p></p><p><p>A nib file describes the visual elements of your application ' s user interface, including windows, views, controls, and Mans Y Others. It can also describe non-visual elements, such as the objects in your application a manage your Windows and Views.</p></p><p><p>Above is the definition on guides, the nib file (the xib File) is a visual element that describes the appearance of the app, contains windows, views, controls, and others, and it can also describe non-visual elements, such as objects that manage windows and views in your app.</p></p><p><p>In other words, xib is a description document, which contains the user interface and user interface related Elements. The main reason for this is that the programmer, because it is "wysiwyg", the programmer does not need to write a bunch of code, and then run out to see the results of the interface elements, which is very inefficient. See the website for more information</p></p><p><p>How does the Xib file achieve "wysiwyg"?</p></p><p><p>In xcode, Open the Xib file as "source code" and discover that it is an xml-encoded file, which means that the essence of the Xib file is to use an XML script that describes the Programmer's settings for the view and its subclasses in xcode, Here we already know how the settings in Xcode are saved, and then how the Xib file is rebuilt into memory in the application Execution.</p></p><p><p>To create a new blank Xib file in xcode, you get the following code:</p></p><p><p></p></p><p><p>Here the XML is parsed and graphically displayed, you can see the Xib file is still relatively complex, the previous expansion of these items are system and version description, can be ignored, focus on the contents of the Blue box (the following explanations are unofficial version, please read carefully).</p></p><p><p></p></p><p><p>We can see directly from the name "ibdocument.integratedclassdependencies" that this array is a description of the ibdocument related class, with the default of Ibproxyobject (related to File's owner) , Ibuiview (related to the main view), if we drag into a label, there will be a description of the Uilabel class, if you choose layout, there will be Nslayoutconstraint.</p></p><p><p></p></p><p><p></p></p><p><p>This piece has metadata, not yet know how to use it, but next, we will see the full picture of the view</p></p><p><p></p></p><p><p>Like the name of rootobjects, This array contains all the objects in the Xib file, the first one is the files Owner, the second is firstresponder, and you can see that they all use proxyobject. Here is a detail about the implementation of the Xib file, when we are in the application who is going to read into and use the user interface, think of our code in the viewcontroller, then Viewcontroller is already in memory, The question of how these configurations read from the Xib file is associated with Viewcontroller is a problem, where you use Proxyobject to do Viewcontroller proxy objects in Xib files, such as</p></p><p><p></p></p><p><p>Then look at the Xml:</p></p><p><p></p></p><p><p>ibclassdescriber, after we set up the association, there will be Iboutlet and ibaction with the xib of the correlation described here, Ibobjectcontainer contains the relationship between the objects,</p></p><p><p>By recording this, the newly created objects (created by Xib Files) are set to mutual reference after Xib is Unarchive.</p></p><p><p>This should be a complicated process, see the following steps for loading the official document Xib File:</p></p><p><p>1 loads the contents of the nib file and its referenced resource file into memory:<br>2 unarchives nib File object graph data and instantiate these Objects. Initializes each new object based on the type of object and its encoding in the Document.</p></p><p><p>3 by initializing the method, it rebuilds the objects in the nib file for all connections (actions, outlets, and bindings).</p></p><p><p>The above 3 steps, iOS and OS X is not the same, here mainly in ios, that is, the nib file created object, reconnect every outlet point, is based on nskeyvaluecoding Protocol, through setvalue:forkey: To Complete.</p></p><p><p>The above is mainly by looking at the Xib file XML data and official documents, completed the Xib file of the content of the general understanding, the details of its implementation and not in-depth analysis, the main purpose let us in the use of Xib file, it is no longer unfamiliar with the Xib file execution error, can be based on the error information to speculate on the wrong place.</p></p><p><p></p></p>Nib Files Store The Objects of Your application ' s User Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.