UINavigationController和UITabBarController共存的例子

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2. {  
  3.     FirstViewController *firstViewController=[[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];  
  4.     UINavigationController *navControl1=[[UINavigationController alloc]initWithRootViewController:firstViewController];  
  5.     [firstViewController release];  
  6.       
  7.     SecondViewController *secondViewController=[[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];  
  8.     UINavigationController *navControl2=[[UINavigationController alloc]initWithRootViewController:secondViewController];  
  9.     [secondViewController release];  
  10.       
  11.     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];  
  12.   
  13.     self.tabBarController = [[[UITabBarController alloc] init] autorelease];  
  14.     self.tabBarController.viewControllers = [NSArray arrayWithObjects:navControl1, navControl2, nil];  
  15.       
  16.     [navControl1 release];  
  17.     [navControl2 release];  
  18.     self.window.rootViewController = self.tabBarController;  
  19.   
  20.     [self.window makeKeyAndVisible];  
  21.     return YES;  
  22. }  


如果某个tabBar不需要navigation,那么用如下代码初始化对应的control

  1. UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease]; 
原文地址:https://www.cnblogs.com/xukunhenwuliao/p/3576213.html