Using storyboard to create a navigation controller and the life cycle of a controller
First, the basic process
Create a new project, the system default host controller inherits from Uiviewcontroller, two files of the master controller are deleted.
In storyboard, the default controller is the view controller, and we need to be the navigation controllers, then the system to delete, drag a navigation controller comes in, the navigation controller in the default first sub-controller is a TableView controller, There is no need, delete it, re-drag three view controller to the interface to connect, simple setup on it.
button, hold down CTRL, and select push on the right interface.
After completing the basic setup, the interface is as follows:
A simple multi-page switch can be achieved with a few simple settings. For the development of a great convenience, but storyboard is not omnipotent, to note in the development, if the last page to add a button, let it jump directly to the previous page there will be a problem.
Hint: Storyboard can do things, use code can do, but the code can do things, storyboard not necessarily be able to do.
Simple interface settings can be done by dragging the controls.
There is a problem with the following connection: (from the back of the controller to the front, only through the code to achieve)
The cause of the problem: (When the click Returns, not the third controller to remove the top of the stack, but the first two controllers, the stack has four controllers, the top of the stack is two).
Second, the life cycle of the controller
Code Simple Description:
1 @interface Njoneviewcontroller () 2 3 @property (nonatomic, strong) Nsarray *foods; 4 @end 5 6 @implementation Njoneviewcontroller 7 8//When the controller's view is loaded, call 9-(void) VIEWDIDLOAD10 {One [super Viewdidloa D];12 NSLog (@ "1 Controller View load Complete"), 13}14 15//Controller's view is about to be displayed when the call is (void) Viewwillappear: (BOOL) animated17 {[Super Viewwillappear:yes];19 NSLog (@ "1 controller view is about to be displayed"), 20}21 22//The Controller's view is fully displayed when the call is at (void) Viewdidappear: (BOOL) Animated2 4 {viewdidappear:animated];26 NSLog (@ "1 controller's view fully displayed"), 27}28 29//Controller's view is about to disappear when the call is (void) viewwilld Isappear: (BOOL) animated31 {[Super viewwilldisappear:animated];33 NSLog (@ "1 controller's view is about to disappear"), 34}35//Controller view completely disappears When calling the Viewdiddisappear-(void): (BOOL) animated37 {[Super viewdiddisappear:animated];39 NSLog (@ "1 controller's view completely disappears") 40}41 42//Controller view is about to be destroyed when the call to (void) viewWillUnload44 {[Super viewwillunload];46}47//Controller's view is completely destroyed when the call 48- (void) viewDidUnload49 {[Super viewdidunload];51Empty the unwanted attributes.//[self.foods release];53 self.foods = nil;54}55,//-(void) Setfoods: (Nsarray *) foods57//{58// if (_foods! = Foods) {///[Foods release];60//_foods = [Foods retain];61//}62//}63 64//Received Memory alert When you call the didReceiveMemoryWarning66 {[void]} {[Super didreceivememorywarning];68}69/**/70 @end
Printing results are as follows
Three important methods:
The controller's view is about to be destroyed when called-(void) viewwillunload{ [Super Viewwillunload];} The controller's view is completely destroyed when called-(void) viewdidunload{ [Super Viewdidunload]; Empty the unwanted attributes// [Self.foods release]; Self.foods = nil;} Called when a memory warning is received-(void) didreceivememorywarning{ [Super didreceivememorywarning];}
Add:
Two differences in memory warnings (compared to proxies):
The agent's memory warning: When something happens to application (when a memory warning is received), its agent is notified, and then the agent notifies it that the Window,window notifies its root controller, and the root controller notifies its child controller. Memory warnings are passed down from top to bottom (can be verified by printing output in two places).
You need to know how its parent class handles memory warnings.
Analog Memory Warning:
Handling of memory Warnings:
Can the controller view be destroyed? How does it know if it can be destroyed? How to judge? It is to determine whether this view is on Windows.
The current one controller is at the top of the stack, and the one controller's view is displayed on the window, and if a memory warning occurs at this point, one is not destroyed because it is on the window.
If at this time a second controller, it creates the corresponding Twoview display to the window, one of the corresponding view moved, at this time if a memory warning occurs, then OneView is no longer displayed on the window, so it will be destroyed.
Special Note: Outlet represents a property, when the controller is created, the property is generally also a value, when the-(void) Viewdidunload method is called, that is, after the controller's view is completely destroyed, all the property data will be emptied. In general, before iOS5, all the properties inside the method are emptied.
Tip: These methods of all controllers are actually a loop.
Using storyboard to create a navigation controller and the life cycle of a controller