【问题标题】:How to skip the root view and go directly to displaying the second view in a UINavigationController hierarchy?如何跳过根视图并直接在 UINavigationController 层次结构中显示第二个视图?
【发布时间】:2015-05-03 23:43:22
【问题描述】:

我正在 ios 上制作一个消息传递应用程序,该应用程序将具有用于不同类型消息的多个文件夹。我将使用导航控制器结构,并希望根视图成为用户可以选择查看哪个文件夹的位置。但是,当我第一次使用导航控制器时,我希望收件箱文件夹视图直接显示(即绕过根视图)。 Apple 的邮件应用程序具有类似的结构(打开时启动收件箱)。我该怎么做?

【问题讨论】:

    标签: ios objective-c uinavigationcontroller


    【解决方案1】:

    这真的取决于第一个视图控制器和第二个视图控制器之间的关系如何。如果你想做这样的事情,为什么不把你的第二个视图控制器作为 UINavigationController 的根控制器。

    无论如何,如果您仍想按照您描述的方式进行操作,您可以使用根视图控制器中的viewDidLoad 方法直接指向第二个视图控制器。但是,它会使 UI 看起来很笨拙。

    【讨论】:

      【解决方案2】:

      尝试使用此代码:

      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      // Override point for customization after application launch.
      
      UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
      
      ViewController *controller1 = [board instantiateViewControllerWithIdentifier:@"firstView"];
      
      UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:controller1];
      
      SecondViewController *secondView = [board instantiateViewControllerWithIdentifier:@"secondView"];
      
      [controller1 addChildViewController:secondView]; 
      
      [self.window setRootViewController:navController];
      
      return YES;
      }
      

      希望这会对你有所帮助。

      【讨论】:

        【解决方案3】:

        把这段代码写在AppDelegate.m的didFinishLaunchingWithOptions

        UIStoryboard *MainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                                 bundle: nil];
        UINavigationController *controller = (UINavigationController*)[MainStoryboard
                                                                       instantiateViewControllerWithIdentifier: @"YourStoryBoardID"];
        
        NeededViewController *need=[MainStoryboard instantiateViewControllerWithIdentifier:@"YourStoryboardID"];         
        [controller setViewControllers:[NSArray arrayWithObject:need] animated:YES];
        self.window.rootViewController=controller;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-10-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-03-06
          • 1970-01-01
          相关资源
          最近更新 更多