The main order of execution methods for a viewcontroller is:
init->loadview->viewdidload->viewwillapper->viewdidapper->viewwilldisapper->viewdiddisapper- >viewdidunload->dealloc
Two about the Init method, generally -(instancetype) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil;
If a companion Xib file is created for Viewcontroller, the direct call to the Init method automatically searches for the corresponding xib file and loads it correctly;
For example: If the Viewcontroller class is MyList, the corresponding xib file is also mylist.xib; So
uiviewcontroller* VC = [[MyList alloc] init]; The actual effect and
uiviewcontroller* VC = [[MyList alloc] initwithnibname:@ "MyList" bundle:nil]; is the same;
However, if the file is not corresponding, it is important to explicitly specify the Xib file name, and it is recommended that you display the specified file name if you are using Xib.
Three about Loadview.
do not call this method by itself, as the SDK documentation says. This method is automatically invoked when the View property is required but the View property is nil. If Viewcontroller is associated with a nib (whether with a xib file or a storyboard file, etc.), the load view from the corresponding nib is assigned to the View property. That is, if you are using Interface Builder to write the interface, then do not rewrite the Loadview method. Subclasses can also override this method if it is a code-written interface and needs to provide a different view hierarchy . In most cases, you don't need to implement this method .
Four before iOS 6, for view controllers that are not displayed at the top level, when a memory warning is received, the system will release the view and invoke Viewwillunload and Viewdidunload. Viewdidload will be called again when the interface is re-entered. So if you're still using MRC, be careful not to alloc some objects in viewdidload because of re-entry.
After iOS 6, when a memory warning is received, some rendering-related memory is automatically reclaimed, and the actual view-related memory does not need to be recycled in most cases. Although this time can also manually self.view = nil, to release memory, but Apple is not recommended to do so, this time back to the memory of the poor, but increased the complexity of processing. At this point, you just need to release some of the memory-intensive member variables based on actual requirements.
If a view controller B is present on view Controller A, then when B is dismiss, the viewwillapper and Viewdidapper of a will not be invoked.
In the comments for this method, there is a paragraph like this:
Note
If A view controller is presented by a view controller inside of a popover, this method was not invoked on the presenting V Iew Controller after the presented controller is dismissed.
Viewcontroller Life cycle Knowledge essentials