1. Create a Tabbed Application. Projects with two tabs are created by default.
2. Add in AppDelegate. h
- @ Property (strong, nonatomic) UINavigationController * NaviView1Controller;
- @ Property (strong, nonatomic) UINavigationController * NaviView2Controller;
3. Modify the didfinishlaunchingwitexceptions function of the AppDelegate. m file. Here we set the corresponding UINavigationController.
- -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
- {
- Self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease];
- // Override point for customization after application launch.
- UIViewController * viewController1 = [[[FirstViewController alloc] initWithNibName: @ "FirstViewController" bundle: nil] autorelease];
- UIViewController * viewController2 = [[[SecondViewController alloc] initWithNibName: @ "SecondViewController" bundle: nil] autorelease];
- Self. tabBarController = [[UITabBarController alloc] init] autorelease];
- Self. tabBarController. viewControllers = @ [viewController1, viewController2];
- Self. window. rootViewController = self. tabBarController;
- [Self. window makeKeyAndVisible];
- Return YES;
- }
After modification:
- -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
- {
- Self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease];
- // Override point for customization after application launch.
- UIViewController * viewController1 = [[[FirstViewController alloc] initWithNibName: @ "FirstViewController" bundle: nil] autorelease];
- ViewController1.title = @ "View1 ";
- Self. NaviView1Controller = [[UINavigationController alloc] initWithRootViewController: viewController1] autorelease];
- UIViewController * viewController2 = [[[SecondViewController alloc] initWithNibName: @ "SecondViewController" bundle: nil] autorelease];
- ViewController2.title = @ "View2 ";
- Self. NaviView2Controller = [[UINavigationController alloc] initWithRootViewController: viewController2] autorelease];
- Self. tabBarController = [[UITabBarController alloc] init] autorelease];
- Self. window. rootViewController = self. tabBarController;
- [Self. window makeKeyAndVisible];
- Return YES;
- }
------------------------
- -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
- {
- Self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease];
- // Override point for customization after application launch.
- UIViewController * viewController1 = [[[FirstViewController alloc] initWithNibName: @ "FirstViewController" bundle: nil] autorelease];
- ViewController1.title = @ "View1 ";
- Self. NaviView1Controller = [[UINavigationController alloc] initWithRootViewController: viewController1] autorelease];
- UIViewController * viewController2 = [[[SecondViewController alloc] initWithNibName: @ "SecondViewController" bundle: nil] autorelease];
- ViewController2.title = @ "View2 ";
- Self. NaviView2Controller = [[UINavigationController alloc] initWithRootViewController: viewController2] autorelease];
- Self. tabBarController = [[UITabBarController alloc] init] autorelease];
- Self. tabBarController. viewControllers = @ [self. NaviView1Controller, self. NaviView2Controller];
- Self. window. rootViewController = self. tabBarController;
- [Self. window makeKeyAndVisible];
- Return YES;
- }