I. How iOS controller view is created (Official document translation)

Source: Internet
Author: User

1. The official description of the Loadview method is as follows:

You should never call this method directly. The view controller calls this method when the It view property is requested and is currently nil. This method loads or creates a view and assigns it to the View property.

You should not call this method directly, when you need to access the controller's view but currently its view is nil, the controller calls this method to load or create a view property that is assigned to it.

The following is a description of the default implementation of the method:

If The view controller has a associated nib file, this method loads the view from the nib file.

A view controller has an associated nib file if the Nibname property returns a Non-nil value, which occurs if the view con Troller is instantiated from a storyboard, if you explicitly assigned it a nib fileusing the InitWithNibName:bundle:meth OD, or if IOS finds a nib file in the app bundle with a name based on the view controller class name.

If The view controller does not has an associated nib file, this method creates a plain UIView object instead.

What if the controller is already connected? A nib file, this method loads the view according to the description of the nib file.

Will the controller be associated? A nib file if its Nibname property returns a non-nil value. When one of the following situations occurs, then the Nibname property of the controller is associated with a nib file.

1) The controller is instantiated from Stroyboard.

2) make it clear when initializing the controller with the Initwithnibname:bundle: Method A nib file is assigned.

3) The system is based on the name of the controller. The associated nib file is found in the package.

if the controller does not find the associated Xib, this method creates a normal view object and assigns a value to the View property of the controller.

If you use Interface Builder to create your views and initialize the view controller, you must not override this method.

If you use Xib to create a view and initialize the controller, you must not override this method

You can override the This method in the order to create your views manually. If you choose to does so, assign the root view of your view hierarchy to the View property. The view you create should is unique instances and should not being shared with any other view controller object. Your Custom implementation of this method should is not a call super.

Can you rewrite this? Manually create views of the controller. If you choose to do this, assign the root view to the controller's view property. The view you create should be unique, no two, and should not be shared with other controller objects. You should not tune in when you customize this implementation of the law. The method of the parent class.

If you want to perform any additional initialization of your views, does so in the Viewdidload method.

If you want to take any additional initialization action on your views, you can enter the line in the Viewdidload method.

2, nibname attribute official analysis
The contains the value specified at initialization timeThe InitWithNibName:bundle:method. The value of this
property is nil.This property contains the value specified when using the Initwithnibname:bundle:? Method initialization. The value of this propertymay be zero.

If you use a nib file to store your view controller's view, it is recommended so specify that nib file explicitly wh En initializing your view controller. However, if you don't specify a nib name, and do not override the Loadview method in your custom subclass, the view contr Oller searches for a nib file using the other means. Specifically, it looks for a nib file with an appropriate name (without the. nib extension) and loads that nib file Whenev Er it view is requested. Specifically, it looks (in order) for a nib file with one of the following names:

If you make the. nib file to store the controller's view, it is recommended that you clearly specify the nib to initialize your controller. And, if you do not specify the name of the nib file, and you do not override the Loadview method in your custom controller class, the controller searches the nib file in other ways, and when its view is accessed, it will?? A proper name (remove the. nib suffix name) to find the nib and load the nib file (if found). It looks for the nib file to make the filename of the next?

> If The View Controller class name ends with the word ' controller ', as-myviewcontroller, it looks for a nib file wh OSE name matches the class name without the word ' Controller ', as in myview.nib.

If the class name of the controller is terminated with the controller word, for example, if the class name is Myviewcontroller, then the system finds the nib file with MyView as its name.

> It looks for a nib file whose name matches the name of the view controller class. For example, if the class name was Myviewcontroller, it looks for a myviewcontroller.nib file.

If the nib file is not found for the first time, the system will use the name of the controller as the name of the nib file to find out if there is a corresponding nib file.

Nib names that include a platform-specific identifier such as ~iphone or ~ipad is loaded only on a device of the CORRESPO Nding type. For example, a nib name of myviewcontroller~ipad.nib was loaded only on ipad. If your app supports both platform types, you must provide versions of your nib files for each platform.

3, the Controller view loading process Summary Official description is as follows:

<1>, the view controller calls its Loadview method. The default implementation of the Loadview method does one of the things:

> If The View controller is associated with a storyboard, it loads the views from the storyboard.

> If The view controller is not associated with a storyboard, an empty UIView object was created and assigned to the VIE W property.

1. When the controller view is accessed, if it is empty, the controller calls Loadview to create the view. The default implementation of the Loadview method does the following two things:

> If the controller has an associated storyboard (that is, created from Stroyboard), the controller's view is loaded from the Stroyboard.

> If the controller has an associated xib, load the controller's view from the Xib.

If the controller does not have an associated stroyboard, an empty view assignment to the controller's view property is created.

<2>, the view controller calls its Viewdidload method, which enables your subclass-perform any additional load-tim E tasks.

2. After Loadview, the controller calls Viewdidload to enable your subclass to perform any additional loading tasks.

I. How iOS controller view is created (Official document translation)

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.