的AppDelegate
window = new UIWindow (UIScreen.MainScreen.Bounds);
navigationController = new UINavigationController();
navigationController.SetNavigationBarHidden (true, true);
loginViewController = new LoginViewController ();
navigationController.AddChildViewController (loginViewController);
if (validToken == true){
Menu = new SlideoutNavigationController();
Menu.MainViewController = new MainNavigationController(new DashBoardViewController(), Menu){ NavigationBarHidden = true };
Menu.MenuViewController = new MenuNavigationController(new SettingViewController(), Menu) { NavigationBarHidden = true };
navigationController.AddChildViewController (Menu);
}
window.RootViewController = navigationController;
window.MakeKeyAndVisible ();
return true;
应用程序的初始启动检查localToken,如果令牌存在则返回true,否则返回false。 if false loginViewController将在初始启动应用程序时加载。 在成功认证后提供用户名和密码 在代码下面运行。
Menu = new SlideoutNavigationController();
Menu.MainViewController = new MainNavigationController(new DashBoardViewController(), Menu){ NavigationBarHidden = true };
Menu.MenuViewController = new MenuNavigationController(new SettingViewController(), Menu) { NavigationBarHidden = true };
NavigationController.PushViewController (Menu, true);
在DashBoardViewController中有LogoutButton。 //应重定向到loginController屏幕。
btn_Logout.TouchUpInside += (sender, e) => {
Console.WriteLine ("Back Pressed");
this.NavigationController.PopViewControllerAnimated(true);
// this.NavigationController.PopToRootViewController (true);
// this.NavigationController.PopToViewController (this,true);
};
它停留在同一个viewController中,它是DashBoardViewController。 想要在按下注销按钮时返回loginviewcontroller。
@All 在此先感谢
答案 0 :(得分:3)
实际上,您正试图在viewControllers堆栈中没有LoginViewController的NavigationController中导航回来。所以你在AppDelegate中添加下一个代码
public void GoToLoginScreen()
{
navigationController.PopToRootViewController(true);
}
并在btn_Logout.TouchUpInside
事件中
btn_Logout.TouchUpInside += (sender, e) =>
{
Console.WriteLine ("Back Pressed");
(UIApplication.SharedApplication.Delegate as AppDelegate).GoToLoginScreen();
};