IOS Study Notes-combining the navigation bar with the tab bar

Source: Internet
Author: User

1. display the label bar and navigation bar directly on the Root View Controller

There is only one Root View Controller. Add the following code to the (BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) lanuchOptions method in the AppDelegate. m file:

// Create the navigation bar object UINavigationController * pNavigation = [[UINavigationController alloc] initWithRootViewController: self. viewController]; // create another Class Object LinAnotherViewController * pAnotherVC = [[LinAnotherViewController alloc] initWithNibName: nil bundle: nil]; // create the Tabbar object UITabBarController * pTabBar = [[UITabBarController alloc] init]; // initialize the array and store the content of the label bar NSArray * pArray = [NSArray arrayWithObjects: pNavigation, pAnotherVC, nil]; // pass the content in the array to the label bar controller pTabBar. viewControllers = pArray; // sets the Root View Controller self. window. rootViewController = pTabBar;

In this case, the view is empty. You can add the corresponding controls, images, and attributes of the navigation bar and label bar according to the previous learning method.

2. Create a New Root View Controller and display the tab bar and navigation bar after the switch interface

When you need to display the label bar and navigation bar after the page Jump, you should set a new Root View, compile and create the corresponding View Controller and navigation bar on it, and add it to the label bar controller. You need to implement the AppDelegate delegate to create a New Root View. First, import the name of the new view, especially the LinAppDelegate. h file.
# Import "LinFirstViewController. h" # import "LinSecondViewController. h" # import "LinThirdViewController. h" // delegate protocol proxy # import "LinAppDelegate. h"
Override-(void) viewDidLoad method:
-(Void) viewDidLoad {[super viewDidLoad]; // create a view object and the corresponding navigation bar object. Assume that both the navigation bar LinFirstViewController * pFirstVC = [[LinFirstViewController alloc] initWithNibName: nil bundle: nil]; UINavigationController * pFirstNavigation = [[UINavigationController alloc] Using: pFirstVC]; LinSecondViewController * using condvc = [[LinSecondViewController alloc] Using: nil bundle: nil]; UINavigationController * implements condnavigation = [[UINavigationController alloc] Using: Implements condvc]; LinThirdViewController * pThirdVC = [[LinThirdViewController alloc] Using: nil bundle: nil]; UINavigationController * direction = [[UINavigationController alloc] direction: pThirdVC]; // initialization array, storage navigation controller NSArray * array = [[NSArray alloc] direction: pFirstNavigation, direction condnavigation, direction, nil]; // initialize the label bar controller UITabBarController * pTabBar = [[UITabBarController alloc] init]; // set the View bar controller (array) pTabBar in the label bar. viewControllers = array; // call Method Based on the delegate Protocol [self goInNemView: pTabBar];} // construct the delegate protocol method and place the tag controller in the New Root View-(void) goInNemView :( id) sender {// obtain the current program UIApplication * app = [UIApplication sharedApplication]; // create the application's delegate object LinAppDelegate * pDelegate = app. delegate; // set the New Root View Controller and use the delegate method to implement the proxy pDelegate. window. rootViewController = sender ;}

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.