【问题标题】:Start a new UIViewController from a UINavigationController从 UINavigationController 启动一个新的 UIViewController
【发布时间】:2015-05-09 14:22:53
【问题描述】:

我有一个UINavigationController,我想从那个导航开始一个新的UIViewController,它有自己的视图控制器。 当我尝试这样做时,我遇到了这个异常

无法在已加载的包中加载 NIB)',其名称和目录为 'Main.storyboardc'''

我正在用这两行代码添加新的视图控制器

            UIViewController *mainViewController =[self.storyboard instantiateViewControllerWithIdentifier:@"CGMainViewController"];
        [self presentViewController:mainViewController animated:NO completion:nil];

有没有什么方法可以从导航控制器开始一个新的UIViewController 而不将其添加到该导航?

【问题讨论】:

    标签: ios objective-c uiviewcontroller uinavigationcontroller nib


    【解决方案1】:

    你可以:

    [self presentViewController:newViewController animated:YES completion:nil];
    

    以模态方式呈现一个新的UIViewController,而不将其添加到UINavigationController 堆栈中

    另外,如果您希望新的 VC 位于新的 UINavigationController 中,那么:

    UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:newViewController];
    [self presentViewController:nc animated:YES completion:nil];
    

    如果您的问题更清楚,我可以提供更多信息,并提供一些您从中得到错误的代码。

    【讨论】:

    • 当我这样做时出现上述异常
    • 如何在代码中创建和初始化newViewController
    【解决方案2】:

    解决了

    我的代码运行正常

    exception 出现是因为storyboard 中新视图控制器的标识符输入错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多