IOS ui-View controller life cycle, load method, and modal view methods

Source: Internet
Author: User

1 #import "ViewController.h"2 #import "SecondViewController.h"3 4 @interfaceViewcontroller ()5 6 @end7 8 @implementationViewcontroller9 Ten  One //the life cycle of the view controller A //How to load a view controller - //Modal View Method -  the /* - //View Controller loading method - -(instancetype) Init - { + Self = [super init]; - if (self) { + //Properties, member variables A //Never initialize the control in this place at     } - return self; - } -  - -(Instancetype) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil - { in //Initialize control (control created with nib file) - //IB (. xib file) No Stroyboard before this file is called a nib file to } +  - -(void) Loadview the { * //Initialize attempted with $ }Panax Notoginseng */ -  the  + //called when the view load is complete, the method that is called in the View controller (pseudo-first) A- (void) Viewdidload { the [Super Viewdidload]; +NSLog (@"Viewdidload"); -      $Self.view.backgroundColor =[Uicolor Cyancolor]; $      -UIButton *btn =[UIButton Buttonwithtype:uibuttontypesystem]; -[Btn Setframe:cgrectmake ( the, -, -, -)]; the[BTN Settitle:@"Next"Forstate:uicontrolstatenormal]; - [btn Setbackgroundcolor:[uicolor orangecolor];Wuyi [btn addtarget:self Action: @selector (Modelmethod) forcontrolevents:uicontroleventtouchupinside]; the [Self.view addsubview:btn]; -      Wu } - #pragmaMark-life Cycle About //called when the view (each time) is about to appear $- (void) Viewwillappear: (BOOL) Animated - { - [Super viewwillappear:animated]; -NSLog (@"Viewwillappear"); A      + } the //view (each time?) ) is called when the completion occurs -- (void) Viewdidappear: (BOOL) Animated $ { the [Super viewdidappear:animated]; theNSLog (@"Veiwdidappear"); the      the } - //the view (each time) is going to disappear when the call in- (void) Viewwilldisappear: (BOOL) Animated the { the [Super viewwilldisappear:animated]; AboutNSLog (@"Viewwilldisappear"); the      the } the //call when the view disappears +-(void) Viewdiddisappear: (BOOL) Animated - { the [Super viewdiddisappear:animated];BayiNSLog (@"Viewdiddisappear"); the      the } -  - #pragmaMark-model View method (Modal view methods) the- (void) Modelmethod the { the     //view toggle, switch to next view theSecondviewcontroller *SECONDVC =[[Secondviewcontroller alloc] init]; -Secondvc.modaltransitionstyle =Uimodaltransitionstylepartialcurl; the  the     //go to a view the [self PRESENTVIEWCONTROLLER:SECONDVC animated:yes completion:nil];94      the      the } the 98 #pragmaMark-other System Method About- (void) didreceivememorywarning { - [Super didreceivememorywarning];101 }102 103 @end

1 #import "SecondViewController.h"2 3 @interfaceSecondviewcontroller ()4 5 @end6 7 @implementationSecondviewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload]; OneNSLog (@"Viewdidload"); A      -Self.view.backgroundColor =[Uicolor Darkgraycolor]; -      theUIButton *btn =[UIButton Buttonwithtype:uibuttontypesystem]; -[Btn Setframe:cgrectmake ( the, -, -, -)]; -[BTN Settitle:@" Back"Forstate:uicontrolstatenormal]; - [btn Setbackgroundcolor:[uicolor whitecolor]; + [btn addtarget:self Action: @selector (Backmethod) forcontrolevents:uicontroleventtouchupinside]; - [Self.view addsubview:btn]; +      A } at- (void) Backmethod - { -     //back to previous view - [self dismissviewcontrolleranimated:yes completion:nil]; - } -  in- (void) didreceivememorywarning { - [Super didreceivememorywarning]; to}

IOS ui-View controller life cycle, load method, and modal view methods

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.