iOS Development Uinavigationcontroller

Source: Internet
Author: User

1 , Overview:

With Uinavigationcontroller, you can easily manage multiple controllers and easily switch between controllers, typically in the "settings" app that comes with your system.

2 , Uinavigationcontroller the simple use

Uinavigationcontroller the use steps :

Complete the following in the Mjappdelegate Didfinishlaunchingwithoptions method:

(1) Initialize Uinavigationcontroller

Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] init];

(2) Set UIWindow Rootviewcontroller to Uinavigationcontroller

Self.window.rootViewController = nav;

(3) Depending on the situation, add the corresponding number of sub-controllers by the push method

Uiviewcontroller *VC1 = [[Uiviewcontroller alloc] init];

Vc1.view.backgroundColor = [Uicolor redcolor];

[Nav pushviewcontroller:vc1 Animated:yes];

Uiviewcontroller *VC2 = [[Uiviewcontroller alloc] init];

Vc2.view.backgroundColor = [Uicolor greencolor];

[Nav PUSHVIEWCONTROLLER:VC2 Animated:yes];

Operating effect:

In the actual development often is to add a viewcontroller to Uinavigationcontroller, click on the button to jump to the next viewcontroller. Click the button to jump to the next Viewcontroller code:

Twoviewcontroller *two = [[Twoviewcontroller alloc] init];

[Self.navigationcontroller Pushviewcontroller: Animated:yes];

After jumping to the next viewcontroller the top navigation bar will automatically appear back button, click to return to the original interface.

3 , Uinavigationcontroller the child controller

Uinavigationcontroller Saves the sub-controller as a stack, and when the Uinavigationcontroller is initialized, it can be Initwithrootviewcontroller by : method to pass in a controller as the root controller, the root controller is always on the bottom of the stack (if there is only one object in the stack, the root controller is also on top of the stack).

@property (nonatomic,copy) Nsarray *viewcontrollers;

@property (nonatomic,readonly) Nsarray *childviewcontrollers;

Use Push method can push a controller into the stack:

-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated:

(BOOL) animated;

In summary, there are three ways to add a sub-controller to a navigation controller:

(1) [Nav Addchildviewcontroller:myviewcontroller];

(2) [Nav Pushviewcontroller:myviewcontroller Animated:yes];

(3) Nav.viewcontrollers = @[Myviewcontroller];

You can also add a sub-controller directly when you initialize the navigation controller:

Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] initwithrootviewcontroller:myviewcontroller];

Use Pop methods to remove the controller:

Remove the controller from the top of the stack :

-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated;

Back to the specified child controller:

-(Nsarray *) popto Viewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;

Back to the root controller (stack bottom controller):

-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated;

iOS Development Uinavigationcontroller

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.