2011-05-07 63 views
4

如何在UITabBarController中插入UINavigationController如何在UITabBarController中插入UINavigationController

目前,我有主UITabBarController裏面應用程序委託declatarion這樣的(所以標籤是主要的)

self.window.rootViewController = self.tabBarController; 

而且裏面一個選項卡,我想插入UINavigationController,並不能得到它。

的代碼池莉構建是這樣的:

  1. MainWindow.xibUITabBarController與標籤對象類型爲UINavigationController(指向NavigationHistory.xib) - 截圖:無效鏈路
  2. NavigationHistory.xib僅包含UINavigationController其中查看指向History.xib
  3. History.xib只有UITableView元素 - 屏幕截圖:無效鏈接

現在UIViewController不顯示我的視圖1視圖,我不知道爲什麼它可能是。也許你有任何線索?或者將我指向完成這種配置的地方。

回答

0

解釋寫appdelegate.m文件中的代碼.....

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    NSMutableArray *Mutablearray = [[NSMutableArray alloc] init]; 

     UIViewController *1st_View = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil]; 

     UINavigationController *Navigation = [[UINavigationController alloc] initWithRootViewController:1st_View]; 

     [Mutablarray addObject:Navigation]; 

     UIViewController *2nd_View = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil]; 

     UINavigationController *Navigation = [[UINavigationController alloc] initWithRootViewController:2nd_View]; 
     [Mutablearray addObject:Navigation]; 

    self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.viewControllers = Mutablearray; 
    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 
0

控制器對象添加到UINavigationController的,並添加navigationcontroller對象的UITabBarController

0

的UINavigationController是一個UIViewController的子類,UITabBarController需要一個UIViewControllers數組(因此UINavigationController);這告訴我,我可以給UITabBarController一個UINavigationControllers(或其子類)的數組,給出所需的交互。

編號:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/

0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
UITabBarController *tab = [[UITabBarController alloc] init]; 


SimpleTableViewController *tableView = [[SimpleTableViewController alloc] init]; 
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tableView]; 
UITabBarItem *item = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:0]; 
nav1.tabBarItem = item; 


AboutViewController *about = [[AboutViewController alloc] init]; 
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:about]; 
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0]; 
nav2.tabBarItem = item2; 

tab.viewControllers = @[nav1,nav2]; 

self.window.rootViewController = tab; 
[self.window makeKeyAndVisible]; 
return YES; 

}

相關問題