The life cycle of the "IOS" Uiviewcontroller

Source: Internet
Author: User

-(void) Loadview;
    • The Loadview method is called when the view of Uiviewcontroller is accessed and is empty.
    • The Loadview method should not be called directly, but is called by the system. It loads or creates a view and assigns it to the Uiviewcontroller view property.
      The following code will cause a dead loop

-(void) loadview{
NSLog (@ "Viewcontroller loadview");
}

    • (void) Viewdidload {
      [Super Viewdidload];
      Additional setup after loading the view, typically from a nib.
      NSLog (@ "Viewcontroller viewdidload");
      Self.view.backgroundColor = [Uicolor Whitecolor];
      }
-(void) viewdidload;
  • When Loadview completes the view load, the Viewdidload method is called, which is executed only once during Uiviewcontroller initialization, where page-related initialization can occur.

    -(void) Viewwillappear: (BOOL) animated;
  • Called when the page will appear. The page will be called every time it appears.
  • When the app has multi-level viewcontroller,pop operation will call the upcoming Viewcontroller of this method, if each time the occurrence of viewcontroller need to refresh the page, can be implemented in this method.

    -(void) viewwilllayoutsubviews;
  • Viewcontroller's view is about to lay out the subviews.

    -(void) viewdidlayoutsubviews;
  • Viewcontroller's view is complete for the subviews layout.

    -(void) Viewdidappear: (BOOL) animated;
  • Called when the page has already appeared. The page is called each time it appears.
  • This method is called when view is added to the view level and multi-view, and the view that is being displayed can be further set here.

    -(void) Viewwilldisappear: (BOOL) animated;
  • Called when the page is going to disappear. may be called multiple times.
  • Called when push or pop is between pages.

    -(void) Viewdiddisappear: (BOOL) animated;
  • Called when the page has disappeared. may be called multiple times.
  • Called when push or pop is between pages.

    -(void) dealloc;
  • Called when the page is destroyed.
  • This method can be used to debug a page if there is a memory leak, and if so, the method will not be called when the page is out of the stack.
  • In this method, you can handle things that need to be released manually, such as the observer's removal.

    Common Cycle Method Execution order

    Since my coding habits are purely code layouts, there is no research on the methods of Xib layout and storyboard layout, the code is as follows

  • (void) Viewdidload {
    [Super Viewdidload];
    Additional setup after loading the view, typically from a nib.
    NSLog (@ "Viewcontroller viewdidload");
    Self.view.backgroundColor = [Uicolor Whitecolor];
    }

-(void) Viewwillappear: (BOOL) animated{
[Super viewwillappear:animated];
NSLog (@ "Viewcontroller viewwillappear");
}

-(void) Viewdidappear: (BOOL) animated{
[Super viewdidappear:animated];
NSLog (@ "Viewcontroller viewdidappear");
}

-(void) Viewwilldisappear: (BOOL) animated{
[Super viewwilldisappear:animated];
NSLog (@ "Viewcontroller viewwilldisappear");
}

-(void) Viewdiddisappear: (BOOL) animated{
[Super viewdiddisappear:animated];
NSLog (@ "Viewcontroller viewdiddisappear");
}

-(void) viewwilllayoutsubviews{
[Super Viewwilllayoutsubviews];
NSLog (@ "Viewcontroller viewwilllayoutsubviews");
}

-(void) viewdidlayoutsubviews{
[Super Viewdidlayoutsubviews];
NSLog (@ "Viewcontroller viewdidlayoutsubviews");
}

    • (void) Didreceivememorywarning {
      [Super didreceivememorywarning];
      Dispose of any resources the can be recreated.
      }

    • Printing results:

Viewcontroller Viewdidload
Viewcontroller Viewwillappear
Viewcontroller Viewwilllayoutsubviews
Viewcontroller Viewdidlayoutsubviews
Viewcontroller Viewdidappear

The above is just a page to show the code and print results, let's look at the page between the jump, the life cycle of execution order.
From page A to page B, page a code:

    • (void) Viewdidload {
      [Super Viewdidload];
      Additional setup after loading the view, typically from a nib.
      NSLog (@ "A viewdidload");
      Self.view.backgroundColor = [Uicolor Whitecolor];
      }

-(void) Viewwillappear: (BOOL) animated{
[Super viewwillappear:animated];
NSLog (@ "A viewwillappear");
}

-(void) Viewdidappear: (BOOL) animated{
[Super viewdidappear:animated];
NSLog (@ "A viewdidappear");
}

-(void) Viewwilldisappear: (BOOL) animated{
[Super viewwilldisappear:animated];
NSLog (@ "A viewwilldisappear");
}

-(void) Viewdiddisappear: (BOOL) animated{
[Super viewdiddisappear:animated];
NSLog (@ "A viewdiddisappear");
}

-(void) viewwilllayoutsubviews{
[Super Viewwilllayoutsubviews];
NSLog (@ "A viewwilllayoutsubviews");
}

-(void) viewdidlayoutsubviews{
[Super Viewdidlayoutsubviews];
NSLog (@ "A viewdidlayoutsubviews");
}

    • (void) Didreceivememorywarning {
      [Super didreceivememorywarning];
      Dispose of any resources the can be recreated.
      }

-(void) Touchesbegan: (Nsset

b page Code:

    • (void) Viewdidload {
      [Super Viewdidload];
      Additional setup after loading the view, typically from a nib.
      NSLog (@ "B viewdidload");
      Self.view.backgroundColor = [Uicolor Whitecolor];
      }

-(void) dealloc{
NSLog (@ "B dealloc");
}

-(void) Viewwillappear: (BOOL) animated{
[Super viewwillappear:animated];
NSLog (@ "B viewwillappear");
}

-(void) Viewdidappear: (BOOL) animated{
[Super viewdidappear:animated];
NSLog (@ "B viewdidappear");
}

-(void) Viewwilldisappear: (BOOL) animated{
[Super viewwilldisappear:animated];
NSLog (@ "B viewwilldisappear");
}

-(void) Viewdiddisappear: (BOOL) animated{
[Super viewdiddisappear:animated];
NSLog (@ "B viewdiddisappear");
}

-(void) viewwilllayoutsubviews{
[Super Viewwilllayoutsubviews];
NSLog (@ "B viewwilllayoutsubviews");
}

-(void) viewdidlayoutsubviews{
[Super Viewdidlayoutsubviews];
NSLog (@ "B viewdidlayoutsubviews");
}

    • (void) Didreceivememorywarning {
      [Super didreceivememorywarning];
      Dispose of any resources the can be recreated.
      }

-(void) Touchesbegan: (Nsset

}

From page A to page B, and then from page B back to page A, print the results:

A Viewdidload
A Viewwillappear
A Viewwilllayoutsubviews
A Viewdidlayoutsubviews
A Viewdidappear
Jump to ****************************.
B Viewdidload
A Viewwilldisappear
B Viewwillappear
B Viewwilllayoutsubviews
B Viewdidlayoutsubviews
A Viewdiddisappear
B Viewdidappear
Go back, ****************************.
B Viewwilldisappear
A Viewwillappear
B Viewdiddisappear
A Viewdidappear
B Dealloc

The life cycle of the "IOS" Uiviewcontroller

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.