IOS miscellaneous pen-7 (do not change the visibility of the status bar in the loadView method of UIViewController), uiviewcontroller
It is best not to change the visibility of the status bar in the loadView method of UIViewController (for example, the status bar changes from display to hidden, or from hidden to display ), this operation causes repeated call of the loadView and viewDidLoad Methods twice.
Although the running effect is correct, the system calls the loadView and viewDidLoad Methods twice in a row, resulting in two uiviews and unnecessary overhead. Why is this? The reason is->
The status bar changes from display to hidden, which means that the available height of the screen is longer and the UIView height of UIViewController needs to be adjusted again. Therefore, the system will call the loadView method again to create a UIView, call the viewDidLoad method again after creation.
The following is a code demonstration and result.
/// ViewController. m // CX do not change the visibility of the status bar in the loadView method of UIViewController. // Created by ma c on 16/3/19. // Copyright©2016 xubaoaichiyu. all rights reserved. // # import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) loadView {NSLog (@" loadView "); // hide the status bar [UIApplication sharedApplication]. statusBarHidden = YES; UIView * view = [[UIView alloc] initWithFrame: [UIScreen mainScreen]. bounds]; view. backgroundColor = [UIColor orangeColor];}-(void) viewDidLoad {[super viewDidLoad]; NSLog (@ "viewDidLoad");} @ end