Life cycle analysis and use of iOS open Viewcontroller

Source: Internet
Author: User

Viewcontroller Load View


When loaded from the storyboards, the Initwithcode is invoked, and the Init is invoked if it does not exist. The Awakefromnib method is then invoked for each object inside.

In the case of alloc out of memory, the Init method is tuned.

Viewcontroller finds the view associated with it in the order that:

First, determine if the subclass overrides the Loadview if there is a direct call. The viewdidload is then tuned to complete the view loading.

If it is external by calling Initwithnibname:bundle to specify NIB filename, Viewcontroller records this nib to create view.

If the Initwithnibname:bundle name parameter is nil, Viewcontroller will find the nib associated with it through the following two steps.

If the class name contains controller, such as Viewcontroller's class name is Myviewcontroller, find whether there is a myview.nib;

Look for files like the Viewcontroller class name, such as Myviewcontroller, to find out if myviewcontroller.nib exists.

If the subclass does not have an overridden Loadview, Viewcontroller will look for or call its default loadview from Stroyboards, and the default Loadview return a blank UIView object.

Note the first step

The Viewcontroller is to determine whether the subclass overrides the Loadview, rather than to determine whether the Viewcontroller view is empty after calling the loadview of the child class. That is, if the subclass rewrites the Loadview, regardless of whether the subclass can get the View,viewcontroller in the Loadview, it will directly adjust viewdidload to complete the view loading.


Viewcontroller Life cycle function

Boot order

Initwithcoder

Call Init if it does not exist

Loadview//If you have rewritten it, it will be called here, and this step can be referenced below


Viewdidload

After the view has just been load and has been connected to the Iboutlet, this place needs to be put into the initialization to accomplish things. [View is not yet displayed]

Viewwillappear

Called when view is about to be displayed.

He is fit to do two things:

1. Load some expensive operations at the last minute

2. Modify Geometric features

Description

[Balabala] is written here if you need to adjust the geometry of the view [changes after rotation].

If it is a long time operation, it is best to open a ready-made operation here.

Viewwilllayoutsubviews

Upcoming

Viewdidlayoutsubviews

When the frame of the view's child view changes [For example: rotating the screen]

This method is often used [did] to handle the layout problems after rotation.

Viewdidappear

Just Show

View Artwork

Related Article

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.