1. 程式人生 > >UINavigationController和UITabBarController共存的例子

UINavigationController和UITabBarController共存的例子

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    FirstViewController *firstViewController=[[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
    UINavigationController *navControl1=[[UINavigationController alloc]initWithRootViewController:firstViewController];
    [firstViewController release];
    
    SecondViewController *secondViewController=[[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
    UINavigationController *navControl2=[[UINavigationController alloc]initWithRootViewController:secondViewController];
    [secondViewController release];
    
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navControl1, navControl2, nil];
    
    [navControl1 release];
    [navControl2 release];
    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];
    return YES;
}


如果某個tabBar不需要navigation,那麼用如下程式碼初始化對應的control

UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];