一、建立一個 Tabbed Application.預設建立的是帶有兩個Tab的工程。
二、在AppDelegate.h裡面添加
- @property (strong, nonatomic) UINavigationController *NaviView1Controller;
- @property (strong, nonatomic) UINavigationController *NaviView2Controller;
三、修改AppDelegate.m檔案的didFinishLaunchingWithOptions函數,在這裡我們設定相應的UINavigationController.
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(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;
- }
修改後:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(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 didFinishLaunchingWithOptions:(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;
- }