1.2 create and load controller view, 1.2 view
Loading priority:
- 1. Use the system loadView method to create a controller View
- 2. If you specify to load a storyboard file as the controller view, the description in the storyboard will be loaded to create the view.
- 3. If you specify to read an xib file as the controller view, load and create the file based on the specified xib file.
- 4. If there is an xib file with the same name as the class name prefix of the controller (that is, the controller is removed), The xib file will be used to create a view of the controller [Example: the control is named TDViewController, And the xib file name is TDView. xib]
- 5. Create an xib file with the same name as the controller.
- 6. If none of the above are available, create an empty widget view;
|
Delayed loading of controller view:
- The Controller's view is delayed loading (lazy loading): loaded when used
- The Controller's view is loaded (loadView is loaded first), and then the viewDidLoad method is called.
- Use the isViewLoaded method to determine whether the view of UIViewController has been loaded.
|
Illustration:
Code Verification:
1 # import "AppDelegate. h "2 # import" TDViewController. h "3 4 @ interface AppDelegate () 5 @ end 6 7 @ implementation AppDelegate 8 9-(BOOL) application :( UIApplication *) application10 didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {11 12 // create window13 self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen]. bounds]; 14 15 // 1. alloc init16 // conclusion: transparent view17 TDViewController * vc = [[TDViewController alloc] init]; 18 19 // 2. create 20 using storyboard // conclusion: The View is white by default (because it is white when sb is dragging the Controller). The 21 UIStoryboard * sb = [UIStoryboard storyboardWithName: @ "Test" bundle: nil]; 22 TDViewController * vc = [sb instantiateInitialViewController]; 23 24 // 3. if you have specified xib, create 25 // conclusion: The description of view and specified xib is the same. 26 TDViewController * vc = 27 [[TDViewController alloc] initWithNibName: @ "TD" bundle: nil]; 28 29 // 4. if there is an xib with the same name, 30 // conclusion: if there is one with the same name, the xib with the same name will be preferentially loaded. Therefore, initWithNibName31 TDViewController * vc = [[TDViewController alloc] init] is not required. 32 33 // 5. 34. Delete controller with the same name. // conclusion: if the same name is removed from the controller, the priority will be higher than the same name. 35 TDViewController * vc = [TDViewController alloc] init]; 36 37 self. window. rootViewController = vc; // You can configure the controller and the Controller. window makeKeyAndVisible]; // display 39 40 return YES; 41}
1 # import "TDViewController. h "2 3 @ interface TDViewController () 4 @ end 5 6 @ implementation TDViewController 7 8-(void) viewDidLoad {9 [super viewDidLoad]; 10} 11 12-(void) didReceiveMemoryWarning {13 [super didReceiveMemoryWarning]; 14} 15 16 // 6. loadView this method is used to override view17 of vc // conclusion: the priority is higher than that of other (xib sb Code). 18-(void) loadView {19 self. view = [[UIView alloc] init]; 20 self. view. backgroundColor = [UIColor purpleColor]; 21 NSLog (@ "loadView"); 22} 23 24 @ end
Loading controller view
The loadView method only uses the code to create the View Controller interface. The loadView method determines whether to call [super loadView] based on actual needs.
Relationship between Screen & Window & View Controller
Memory warning Processing
If you think this article is helpful to you, click "recommended" in the lower right corner, ^ _ ^
Author: Loto)
Source: http://www.cnblogs.com/shorfng/
The copyright of this article is shared by the author and the blog. You are welcome to repost this article, but you must keep this statement without the author's consent and provide a connection to the original article on the article page.
If you have any questions, please send an e-mail to shorfng@126.com to contact me.
By: Loto)