Each time you access a Uiviewcontroller view (such as Controller.view, Self.view) and the view is Nil,loadview the method is called.
The premise is that the uiviewcontroller of the view is not empty.
Role:
The Loadview method is used to create a uiviewcontroller view
That is, we can use the view from the definition VC
If we do not overload this method. It calls "Super Loadview"; it returns a view. The inside implementation is:
1> It first looks for the Xib file associated with Uiviewcontroller, and creates Uiviewcontroller view by loading the Xib file.
- If the Xib file name is specified in the initialization uiviewcontroller, the corresponding xib file is loaded according to the Xib file name passed in
- [[Mjviewcontroller alloc] initwithnibname:@"Mjviewcontroller" bundle:nil];
- If the Xib file name is not clearly transmitted, the Xib file with the same name as Uiviewcontroller will be loaded
- [[Mjviewcontroller alloc] init]; //Load Mjviewcontroller.xib
2> if the associated xib file is not found, a blank uiview is created and then assigned to the Uiviewcontroller view property, roughly as follows
- Self.view = [[[UIView alloc] Initwithframe:[uiscreen mainscreen].applicationframe] autorelease];
- The value of the Applicationframe is: {{x = 0, y = +}, {width = +, height = 460}}
[Super Loadview] the contents of 1> and 2> are roughly completed.
We all know that Uiviewcontroller view can be created by xib files, but in some cases xib is not so flexible, so sometimes we want to create uiview through code, such as:
- Self.view = [[[UIWebView alloc] Initwithframe:[uiscreen mainscreen].applicationframe] autorelease];
If you want to create a Uiviewcontroller view by code, rewrite the Loadview method, and do not need to call [Super Loadview], because it is mentioned in the 3rd: if there is no Xib file, [Super Loadview] A blank UIView is created by default. Since we are going to customize UIView through code, there is no need to create a blank uiview in advance to save unnecessary overhead. The right approach should be this:
- -(void) Loadview {
- Self.view = [[[UIWebView alloc] Initwithframe:[uiscreen mainscreen].applicationframe] autorelease];
- }
There is no need to call [Super Loadview], and you can call it without error, just cause some unnecessary overhead.
To summarize, Apple's design method is to give us a custom Uiviewcontroller view.
About when Loadview in Uiviewcontroller is called