1.loadView
This is the method that the view controller uses to load the root view;
If you need to use a custom view as the root view, you do not need to call the parent class's implementation of the method ([Super Loadview]); Directly define the custom view through Self.view as the root view of the view controller;
A simple response event in a custom view should also be handled by the view controller, written in this method;
2.viewDIdLoad
The method is triggered when the view controller's root view is loaded, (that is, the method is called immediately after the Loadview call is completed);
The implementation of the method needs to be called by the parent class;
This method can make some simple settings for the root view, such as background color and so on.
3.viewwillappear: (BOOL) animated; triggers when the view controller's root view is about to be displayed ;
4.viewdidappear: (BOOL) animated; // triggers when the view controller's root view is displayed ;
5.viewWillDisappear: (BOOL) animated; triggers when the view controller's root view is going to disappear ;
6.viewDidDisappear: (BOOL) animated; triggers when the view controller's root view disappears ;
7.didReceiveMemoryWarning; // triggered when a memory warning is received at this point, you need to release the temporarily unused resources , and can reconstruct objects ;
1 -(void ) didreceivememorywarning { 2 [super didreceivememorywarning]; 3 if ([self isviewloaded] &&!< Span style= "color: #000000;" >self.view.window) { 4 self.view = nil;
5 " 6 7 // 8 //
#pragma mark-- the method associated with screen rotation
8. set whether the current interface changes when the device rotates, supports rotation
-(BOOL) shouldautorotate {
return YES;
}
9. set the direction of rotation supported by the current interface . must depend on the direction the current application supports ;
-(nsuinteger) supportedinterfaceorientations {
return uiinterfaceorientationmaskall;//Support All directions
}
when the screen rotates , the iOS8 is effective after the
-(void) Viewwilltransitiontosize: (cgsize) size withtransitioncoordinator: (ID< Uiviewcontrollertransitioncoordinator>) Coordinator {
//size Indicates the size of the screen after rotation ;
NSLog(@ "%@",nsstringfromcgsize(size));//output the screen size at this time;
}
About methods to call the parent class:
The implementation of the method by the parent class can be used to help us with some initialization of the view (some initialization work we do not know, nor see, so be sure to call);
When overriding a method inherited from a parent class , if you do not know how the parent class implements the method , Remember to use Super to invoke the implementation of the method ;
On the method of [super XXX] Call the parent class method, if you do not need to add additional content, the parameters of the direct return yes is OK.
Add one:
-(instancetype) Initwithnibname: (nsstring *) Nibnameornil Bundle: (nsbundle *) Nibbundleornil ;
This is the specified initialization method of the view controller, regardless of which method is called, the initialization method will be triggered;
-(Instancetype) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil { = [ Super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) { // Complete this class's unique initialization operation. } return self ;}
Methods that are triggered during view loading (loadview/viewdidload/didreceivememorywarning)