iOS Development Storyboard ~ ~ Using storyboard to create a navigation controller and the life cycle of a controller

Source: Internet
Author: User

First, the basic process

Create a new project with storyboard, the system default host controller inherits from the Uiviewcontroller, the main controller two files 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. (TableView Controller and view controller connection root When you drag a view controller control after you deleteit)

button, hold down CTRL, and select push on the right interface.

After completing the basic setup, the interface is as follows:

the Navigation controller is the root view of the uiwindows. The first view controllers are the root views of the navigation controlsA 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) viewdidload {One [super viewdidload]; NSLog (@ "1 Controller View load complete"); 13} 14 15//Controller's view is about to be displayed when the call is (void) Viewwillappear: (BOOL) animated + [Super Viewwillappear:yes]; NSLog (@ "1 control The view of the system will be displayed "); 20} 21 22//The Controller's view is fully displayed when the call is at (void) Viewdidappear: (BOOL) animated @ [Super viewdidappear:animated]; "1 controller's view fully displayed"); 27} 28 29//Controller's view is about to disappear when the call is (void) Viewwilldisappear: (BOOL) animated {[Super viewwilldisappear:animated]; 33 NSLog (@ "1 controller's view is about to disappear"); 34} 35//The controller's view completely disappears when the call to Viewdiddisappear (void) is: (BOOL) animated PNS {[Super viewdiddisappear:animated]; nslo G (@ "1 controller's view completely disappears"); 40} 41 42//The view of the controller is about to be destroyed when the call is (void) viewwillunload [[Super Viewwillunload]; 46} 47//Controller view is completely destroyed when the call 48 -(void) viewdidunload [Super Viewdidunload]; 51//emptying of unwanted properties 52//[Self.foods release]; Self.foods = nil; //-(void) Setfoods: (Nsarray *) Foods//{//if (_foods! = Foods) {//[foods release];//_foods = [ Foods retain]; 61//} 62//} 63 64//When the memory warning is received, the call is (void) didreceivememorywarning, [[Super didreceivememorywarning]; 68} 69/ **/@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.

iOS Development Storyboard ~ ~ Using storyboard to create a navigation controller and the life cycle of a controller

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.