IOS UINavigationController-navigation bar controller, ioscontroller jump

Source: Internet
Author: User

IOS UINavigationController-navigation bar controller, ioscontroller jump

The parent class of any controller is UIViewController, and the navigation bar controller is no exception. It is a subclass of UIViewController.

1. What is a navigation bar controller? What is the role?

UINavigationController is also a controller. UIViewController is displayed in the management view. UINavagationController is used to manage the switching of some uiviewcontrollers. That is to say, different UIViewController switches are implemented under the management of UINavigationController.

These managed uiviewcontrollers are the sub-controllers of the UINavagationController.

A UINavagationController must have at least one sub-controller. We call this sub-controller the root controller RootViewController of this navigation bar controller. When initializing a UINavagationController, the initialization method will allow you to set a Root View RootViewController. For example:

UIViewController * rootViewController = [[UIViewController alloc] init];

UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController: rootViewController];

Note: The navigation bar controller is a management controller that does not display content.

 

2. shows the structure of the navigation bar controller.

A Navigation bar controller consists of three parts: Navigation bar, self-controller view (Custum content), and Navigation toolbar. Custumcontent can be placed on the View Controller, and the controller can display its own View. Since UINavigationController inherits from UIViewController, its structure is the same as that of UIViewController, place view and other things on it.

The Navigation toolbar is usually hidden by default. Therefore, after a Navigation bar controller is added, you can only see the Navigationbar above. The second figure is shown below.

  

  

  

 

 

3. hierarchical relationship analysis of navigation bar Controllers

  

  

UINavigationController has a property viewControllers, @ property (nonatomic, copy) NSArray * viewControllers; // The current view controller stack. (Excerpted from The document ). ViewControllers is an array that stores all the sub-controllers of the Controller in the navigation bar and manages the stack structure from the Controller. That is, the sub-controllers are first added at the bottom.

  

VisibleViewController is the current attempt controller. Sometimes we use the push statement to push to a certain attempt Controller Interface. At this time, visibleViewController is the attempt controller.

TopViewController is the top-level sub-View Controller.

 

 

4. How can I switch from a controller to the next Controller under the control of the navigation bar?

1. First, let's take a look at how to complete the process from a View Controller to another view controller without navigation bar control:

Switching from the first view controller to the second view controller, In the first attempt controller [self presentViewController: animated: completion: ^ {}]; this method switches from the first view controller to the second view controller.

To switch back from the second view controller, call [self dismissViewControllerAnimated: completion :^{}] In the second view controller.

2. How can I switch between two view controllers under the control of the navigation bar controller?

FirstViewController and SencondViewController are two instantiated classes, each of which has its own navigation bar controller. to switch from FirstViewController to SencondViewController, introduce the SencondViewController header file in FirstViewController, create a SencondViewController object sencondVC and use [self. navigationController pushViewController: secondVC animated: YES]; The switch is completed.

 

5. common attributes and methods of navigation bar Controllers

1. common attributes

@ Property (nonatomic, readonly, retain) UIViewController * topViewController; // the top-level view Controller

@ Property (nonatomic, readonly, retain) UIViewController * visibleViewController; // View Controller currently displayed

@ Property (nonatomic, copy) NSArray * viewControllers; // all view Controllers

@ Property (nonatomic, readonly) UINavigationBar * navigationBar; // navigation bar 2. Common Methods:

  

  

6. In addition, the navigation bar controller also has its own delegate method. For details, see the document.

After setting proxy

-(Void) navigationController :( UINavigationController *) navigationController willShowViewController :( UIViewController *) viewController animated: (BOOL) animated; // called when the View Controller is to be displayed.

-(Void) navigationController :( UINavigationController *) navigationController didShowViewController :( UIViewController *) viewController animated: (BOOL) animated; // an attempt to control the call is displayed.

 

 

 

If you are a beginner in iOS, please kindly advise.

Related Article

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.