【问题标题】:PresentViewController to a ViewController with a different NavigationController but on the same storyboardPresentViewController 到具有不同 NavigationController 但在同一个故事板上的 ViewController
【发布时间】:2015-03-16 10:21:46
【问题描述】:

我在使用简单的 Xamarin Studio Storyboards 概念时遇到了问题。请参阅下面的屏幕截图以获取视觉效果,并查看downloadable source code here

假设我有一个带有 MainViewController 的 NavigationController。这在我的故事板中可见。我想要一个按钮,当按下它时,会弹出一个带有 RedViewController 的新 NavigationController。我还希望 RedViewController 在与 MainViewController 相同的情节提要上。在这个项目中,我尝试这样做,但出于某种原因,当我这样做时:

var myStoryboard = AppDelegate.Storyboard;
// Instatiating View Controller with Storyboard ID 'StuffViewController'
RedViewController = myStoryboard.InstantiateViewController ("RedViewController") as RedViewController;
RedViewController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
this.PresentViewController(RedViewController, true, null);

RedViewController 没有它的导航控制器。出现时 RedViewController 的导航控制器为空!我在那里做错了什么?

现在,当我在完全独立的情节提要中创建 NavigationController 和 BlueViewController 时,它可以正常工作。当我按下蓝色按钮时,它会转到 BlueViewController 并正确显示它是 NavigationController。为什么这个工作,而另一个不工作?我能看到的唯一区别是它们位于不同的故事板上。

UIStoryboard storyBoard = UIStoryboard.FromName ("BlueStoryboard", null);
UIViewController controller = storyBoard.InstantiateInitialViewController () as UIViewController;
controller.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
this.PresentViewController (controller, true, null);

ViewController 可以呈现一个新的 NavigationController 和 ViewController ViewController,名为“Red”,带有导航栏

【问题讨论】:

    标签: ios uinavigationcontroller xamarin.ios xamarin storyboard


    【解决方案1】:

    当你实例化你的新视图控制器时,你需要实例化UINavigationController,而不是RedViewController

    在您的“蓝色”代码的情况下,您实例化 initialViewController - 这是包含蓝色控制器的导航控制器。

    你想要

    RedViewNavigationController = myStoryboard.InstantiateViewController ("RedViewNavigationController") as UINavigationController;
    

    其中“RedViewNavigationController”是嵌入红色视图控制器的导航控制器的标识符。

    【讨论】:

      【解决方案2】:

      如果你想呈现红色控制器及其导航控制器,你应该实例化导航控制器(反过来,它会实例化红色控制器),并呈现它。

      【讨论】:

        猜你喜欢
        • 2014-11-11
        • 1970-01-01
        • 2013-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-13
        • 2016-12-18
        • 1970-01-01
        相关资源
        最近更新 更多