问题描述
我正在使用导航控制器来管理xamarin.ios项目的情节提要,我需要从动态原型表(已定制表源单元格)中切换到由NavigationControllers驱动的视图控制器,因此未显示导航栏,使我失去了返回上一个控制器的能力。
public void ApriStoryBoard(string x)
{
var storyboard = UIStoryboard.FromName("Main",null);
var viewController = storyboard.InstantiateViewController(x); // Your view controller here
UIApplication.SharedApplication.KeyWindow.RootViewController = viewController;
}
我目前正在尝试使用PushViewController,但是它不起作用..
public void ApriNavigationController()
{
ThisSchedaView x = this.Storyboard.InstantiateViewController("QuestaSchedaNav") as ThisSchedaView;
NavigationController.PushViewController(x,true);
}
解决方法
如果使用 NavigationController 进行导航:
NavigationController.PushViewController(secondViewController,true);
您可以使用以下方式回到以前的vontroller:
NavigationController.PopViewController(true);
//or specify the needed controller
NavigationController.PopToViewController(previousController,true);
如果使用模型视图导航到下一个控制器,如下所示:
PresentModalViewController(secondViewController,true);
您可以使用以下方法返回上一个控制器:
DismissModalViewController(true);
===============================更新#1 ============ =================
如果使用NavigationCotroller
进行导航,则其条件应为根控制器。
例如在 .StoryBoard 中:
或 .cs 代码中的以下内容:
...
this.Window.RootViewController = new UINavigationController(xxxController);
...
,
我正在尝试使用这段代码打开登录页面,但是没有打开它。
var storyboard = UIStoryboard.FromName("Main",null);
var secondViewController = storyboard.InstantiateViewController(x);
NavigationController.PushViewController(secondViewController,true);