<tfoot id='O7zch'></tfoot>

<legend id='O7zch'><style id='O7zch'><dir id='O7zch'><q id='O7zch'></q></dir></style></legend>

        <bdo id='O7zch'></bdo><ul id='O7zch'></ul>
      1. <small id='O7zch'></small><noframes id='O7zch'>

        <i id='O7zch'><tr id='O7zch'><dt id='O7zch'><q id='O7zch'><span id='O7zch'><b id='O7zch'><form id='O7zch'><ins id='O7zch'></ins><ul id='O7zch'></ul><sub id='O7zch'></sub></form><legend id='O7zch'></legend><bdo id='O7zch'><pre id='O7zch'><center id='O7zch'></center></pre></bdo></b><th id='O7zch'></th></span></q></dt></tr></i><div id='O7zch'><tfoot id='O7zch'></tfoot><dl id='O7zch'><fieldset id='O7zch'></fieldset></dl></div>
      2. 自定义 UITabBarController 和 UINavigationController

        时间:2023-06-13

        <small id='mBQBt'></small><noframes id='mBQBt'>

            <tbody id='mBQBt'></tbody>
        • <tfoot id='mBQBt'></tfoot>

            <bdo id='mBQBt'></bdo><ul id='mBQBt'></ul>
            <i id='mBQBt'><tr id='mBQBt'><dt id='mBQBt'><q id='mBQBt'><span id='mBQBt'><b id='mBQBt'><form id='mBQBt'><ins id='mBQBt'></ins><ul id='mBQBt'></ul><sub id='mBQBt'></sub></form><legend id='mBQBt'></legend><bdo id='mBQBt'><pre id='mBQBt'><center id='mBQBt'></center></pre></bdo></b><th id='mBQBt'></th></span></q></dt></tr></i><div id='mBQBt'><tfoot id='mBQBt'></tfoot><dl id='mBQBt'><fieldset id='mBQBt'></fieldset></dl></div>

                1. <legend id='mBQBt'><style id='mBQBt'><dir id='mBQBt'><q id='mBQBt'></q></dir></style></legend>

                  本文介绍了自定义 UITabBarController 和 UINavigationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在为 iOS5 及更高版本开发应用程序,我不使用情节提要或 IB.我正在创建一个自定义 UITabBarController 并在我的 AppDelegate 中放入 4 个视图控制器,其中只有 1 个 UINavigationController (不知道为什么).

                  I'm developing an app for iOS5 and up and I don't use storyboards or IB. I'm creating a custom UITabBarController and in my AppDelegate I'm putting in it 4 view controllers with only 1 UINavigationController (can't tell why).

                  这导致我只能从 first 选项卡推送新的 VC,这显然是打包到一个名为 navControllerUINavigationController 中>:

                  It results in a behaviour where I can push new VC only from the first tab, which is apparently, packed into a UINavigationController called navController:

                  SGTabBarController *tabBarController = [[SGTabBarController alloc] init];
                  
                      SGHomeViewController* vc1 = [[SGHomeViewController alloc] init];
                      SGChooseOSAgainViewController* vc3 = [[SGChooseOSAgainViewController alloc] init];
                      SGSmsServicesViewController* vc4 = [[SGSmsServicesViewController alloc] init];
                      SGSupportViewController *vc5 = [[SGSupportViewController alloc] init];
                      navController = [[UINavigationController alloc] initWithRootViewController:vc1];
                  
                      NSArray* controllers = [NSArray arrayWithObjects:navController, vc3, vc4, vc5, nil];
                      tabBarController.viewControllers = controllers;
                  
                      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
                      self.window.rootViewController = tabBarController;
                      [navController setNavigationBarHidden:YES animated:NO];
                      [self.window makeKeyAndVisible];
                  

                  这是为什么呢?我应该为每个选项卡创建一个单独的 UINavigationController 吗?我从 Apple 的文档中获取了这段代码.

                  Why is that? Should I create a separate UINavigationController for each tab? I took this code from Apple's documentation.

                  推荐答案

                  是的,你可以.尝试类似这样的代码在你的 UITabBarController.m 中:

                  Yes, you can. Try something like this code in yourUITabBarController.m:

                  - (void)viewDidLoad
                  {
                    [super viewDidLoad];
                      
                    NSMutableArray* sectionViewControllers = nil;
                    NSArray* controllers = [self controllers];
                    UIViewController* controller = nil;
                    
                    for (controller in controllers)
                    {
                      if (sectionViewControllers == nil)
                        sectionViewControllers = [NSMutableArray arrayWithCapacity:0];
                      
                      UINavigationController* navigationController = [[UINavigationController allocWithZone:[self zone]] initWithRootViewController:controller];
                      
                      navigationController.navigationBarHidden = YES;
                      
                      [sectionViewControllers addObject:navigationController];
                      [navigationController release];
                    }
                    
                    self.viewControllers = sectionViewControllers;
                  }
                  
                  - (NSArray*)controllers
                  {
                    if (!_controllers)
                      _controllers = [NSArray arrayWithObjects:[self tabController1], [self tabController2], nil];
                    return _controllers;
                  }
                  

                  这在你的 AppDelegate.m 中:

                  and this in you AppDelegate.m:

                  self.window.rootViewController = self.yourUITabBarController;
                  

                  这篇关于自定义 UITabBarController 和 UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何更改选中和未选中的标签栏图像颜色 下一篇:iOS:删除 UINavigationBar 动画

                  相关文章

                2. <legend id='wXj2S'><style id='wXj2S'><dir id='wXj2S'><q id='wXj2S'></q></dir></style></legend>

                      <bdo id='wXj2S'></bdo><ul id='wXj2S'></ul>
                    1. <small id='wXj2S'></small><noframes id='wXj2S'>

                      <tfoot id='wXj2S'></tfoot>
                    2. <i id='wXj2S'><tr id='wXj2S'><dt id='wXj2S'><q id='wXj2S'><span id='wXj2S'><b id='wXj2S'><form id='wXj2S'><ins id='wXj2S'></ins><ul id='wXj2S'></ul><sub id='wXj2S'></sub></form><legend id='wXj2S'></legend><bdo id='wXj2S'><pre id='wXj2S'><center id='wXj2S'></center></pre></bdo></b><th id='wXj2S'></th></span></q></dt></tr></i><div id='wXj2S'><tfoot id='wXj2S'></tfoot><dl id='wXj2S'><fieldset id='wXj2S'></fieldset></dl></div>