TabBarController and NavigationController can coexist in three ways.

Source: Internet
Author: User

You must use NavigationController in TabBarController to implement view navigation in TabbarController. I have summarized three methods for your reference. First, use TabBarController to create an XIB file and pull the corresponding Tabbar on the xib. In this case, you only need to establish a corresponding relationship between the previous page and the next page. The following code creates a ing: EDUThreeViewController * th = [[EDUThreeViewController alloc] initWithNibName: @ "EDUThreeViewController" bundle: nil]; UINavigationController * n = [[UINavigationController alloc] initWithRootViewController: th]; [self presentViewController: n animated: YES completion: nil]; but now I know that only the next view can be displayed. Type 2: Create the XIB of TabBarController and drag the NavigationController to the TabBar. (You can drag NavigationControlle or TabBarItem as needed, the NavigationBar is automatically displayed when you drag the page of NavigationController ). For example, callback. However, the TabBar will appear in the next-level view. If you do not need it, you can use the code to remove it. All the code is as follows: EDUStuViewController * stuViewController = [[EDUStuViewController alloc] init]; stuViewController. hidesBottomBarWhenPushed = YES; // remove TabBar [self. navigationController pushViewController: stuViewController animated: YES]; 3: All mentioned above are in the XIB view. Here we will talk about implementation in code. Here we need to combine TabBarController and NavigationController in delegate. The instance code is as follows:-(BOOL) application :( UIApplication *) applicationdidfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {self. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; // Override point for customization after application launch. // The first view on the TabBar www.2cto.com EDUaaViewController * aa = [[EDUaaViewController alloc] initWithNibName: @ "EDUaaViewController" bundle: nil]; // Add ViewController to NavigationController UINavigationController * aaNav = [[UINavigationController alloc] initWithRootViewController: aa]; // EDUbbViewController * bb = [[EDUbbViewController alloc] initWithNibName: @ "EDUbbViewController" bundle: nil]; // Add ViewController to NavigationController UINavigationController * bbNav = [[UINavigationController alloc] handler: bb]; // Add navigationController to the array NSArray * controllerArray = [[NSArray alloc] handler: aaNav, bbNav, nil]; // create a TabBarController. h first declare tabBarController = [[UITabBarController alloc] init]; tabBarController. delegate = self; // Add the arrays of navigationController to tabBarController. viewControllers = controllerArray; tabBarController. selectedIndex = 0; [(UITabBarItem *) [tabBarController. tabBar. items objectAtIndex: 0] setTitle: @ "health check data"]; [(UITabBarItem *) [tabBarController. tabBar. items objectAtIndex: 1] setTitle: @ ""]; // UIViewController * activeController = tabBarController. selectedViewController; [self. window addSubview: tabBarController. view]; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; return YES ;}

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.