IOS miscellaneous pen-7 (do not change the visibility of the status bar in the loadView method of UIViewController), uiviewcontroller

Source: Internet
Author: User

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

 

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.