【问题标题】:How to insert UINavigationController inside UITabBarController如何在 UITabBarController 中插入 UINavigationController
【发布时间】:2011-08-20 17:34:06
【问题描述】:

如何在UITabBarController 中插入UINavigationController

目前我有 main UITabBarController 在这样的应用程序委托中声明(所以选项卡是主要的)

self.window.rootViewController = self.tabBarController;

我想在其中一个标签中插入UINavigationController,但无法得到它。

代码结构如下:

  1. MainWindow.xib 带有UITabBarController 对象,标签类型为UINavigationController(指向NavigationHistory.xib) - 屏幕截图:无效链接
  2. NavigationHistory.xib 仅包含 UINavigationController 其中 view 指向 History.xib
  3. History.xib 只有UITableView 元素 - 屏幕截图:无效链接

现在UIViewController 不显示我的 View1 视图,我不知道为什么会这样。也许你有任何线索?或将我指向完成此类配置的位置。

【问题讨论】:

    标签: ios layout uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    【讨论】:

    • 才半年,那个链接就已经失效了。 iOS 肯定会快速发展!
    【解决方案2】:

    在 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;
    }
    

    【讨论】:

      【解决方案3】:

      将控制器对象添加到 UINavigationController,并将导航控制器对象添加到 UITabBarController

      【讨论】:

        【解决方案4】:

        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/

        【讨论】:

          【解决方案5】:
          - (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;
          

          }

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-11-24
            • 1970-01-01
            • 2020-04-03
            • 2014-07-28
            • 2019-03-03
            • 1970-01-01
            相关资源
            最近更新 更多