使用不同的NavigationController但在同一故事板上的ShowController到ViewController

时间:2015-01-18 04:46:38

标签: ios uinavigationcontroller xamarin.ios xamarin storyboard

我在使用简单的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的导航控制器为空!我在那里做错了什么? enter image description here

现在我创建了一个NavigationController& BlueViewController在一个完全独立的故事板中工作正常。当我按下蓝色按钮时,它会转到BlueViewController并正确显示它的NavigationController。为什么这个工作但另一个不工作?我能看到的唯一区别是它们位于不同的故事板上 enter image description here

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"带导航栏

Main Storyboard with additional Red NavigationController/ViewController Blue Storyboard, that works as desired.

2 个答案:

答案 0 :(得分:1)

如果您想要将红色控制器与其导航控制器一起呈现,您应该实例化导航控制器(反过来,它将实例化红色控制器)并呈现它。

答案 1 :(得分:1)

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

对于你的蓝色'您实例化initialViewController的代码 - 这是包含蓝色控制器的导航控制器。

你想要

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

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

相关问题