UINavigationController and UITabBarController are used together

Source: Internet
Author: User

1. Create a Tabbed Application. Projects with two tabs are created by default.

2. Add in AppDelegate. h

 

  1. @ Property (strong, nonatomic) UINavigationController * NaviView1Controller;
  2. @ Property (strong, nonatomic) UINavigationController * NaviView2Controller;


3. Modify the didfinishlaunchingwitexceptions function of the AppDelegate. m file. Here we set the corresponding UINavigationController.

 

  1. -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
  2. {
  3. Self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease];
  4. // Override point for customization after application launch.
  5. UIViewController * viewController1 = [[[FirstViewController alloc] initWithNibName: @ "FirstViewController" bundle: nil] autorelease];
  6. UIViewController * viewController2 = [[[SecondViewController alloc] initWithNibName: @ "SecondViewController" bundle: nil] autorelease];
  7. Self. tabBarController = [[UITabBarController alloc] init] autorelease];
  8. Self. tabBarController. viewControllers = @ [viewController1, viewController2];
  9. Self. window. rootViewController = self. tabBarController;
  10. [Self. window makeKeyAndVisible];
  11. Return YES;
  12. }

After modification:

  1. -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
  2. {
  3. Self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease];
  4. // Override point for customization after application launch.
  5. UIViewController * viewController1 = [[[FirstViewController alloc] initWithNibName: @ "FirstViewController" bundle: nil] autorelease];
  6. ViewController1.title = @ "View1 ";
  7. Self. NaviView1Controller = [[UINavigationController alloc] initWithRootViewController: viewController1] autorelease];
  8. UIViewController * viewController2 = [[[SecondViewController alloc] initWithNibName: @ "SecondViewController" bundle: nil] autorelease];
  9. ViewController2.title = @ "View2 ";
  10. Self. NaviView2Controller = [[UINavigationController alloc] initWithRootViewController: viewController2] autorelease];
  11. Self. tabBarController = [[UITabBarController alloc] init] autorelease];
  12. Self. window. rootViewController = self. tabBarController;
  13. [Self. window makeKeyAndVisible];
  14. Return YES;
  15. }
------------------------
    1. -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
    2. {
    3. Self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease];
    4. // Override point for customization after application launch.
    5. UIViewController * viewController1 = [[[FirstViewController alloc] initWithNibName: @ "FirstViewController" bundle: nil] autorelease];
    6. ViewController1.title = @ "View1 ";
    7. Self. NaviView1Controller = [[UINavigationController alloc] initWithRootViewController: viewController1] autorelease];
    8. UIViewController * viewController2 = [[[SecondViewController alloc] initWithNibName: @ "SecondViewController" bundle: nil] autorelease];
    9. ViewController2.title = @ "View2 ";
    10. Self. NaviView2Controller = [[UINavigationController alloc] initWithRootViewController: viewController2] autorelease];
    11. Self. tabBarController = [[UITabBarController alloc] init] autorelease];
    12. Self. tabBarController. viewControllers = @ [self. NaviView1Controller, self. NaviView2Controller];
    13. Self. window. rootViewController = self. tabBarController;
    14. [Self. window makeKeyAndVisible];
    15. Return YES;
    16. }

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.