我创建了一个具有登录名的应用程序。
它从欢迎 View Controller 开始,检查用户是否登录,如果没有,则打开登录 View Controller 。如果用户已登录,或者一旦登录,就会将用户推送到主视图 Controller ,如下所示。
App Delegate (did finish launching)
self.welcomeViewController = [[APPWelcomeViewController alloc] init];
self.homeViewController = [[APPHomeViewController alloc] initWithNibName:@"APPHomeViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.welcomeViewController];
self.navController.navigationBarHidden = YES;
self.window.rootViewController = self.navController;
用户登录后,它会推送主视图。
// Push the homeViewController onto the navController
[self.navController pushViewController:self.homeViewController animated:YES];
到目前为止一切正常。然后,我使用模态视图 Controller 进行设置,其中包括一个注销按钮。用户注销运行如下:
// Log the user out
[User logOut];
// Then we need to remove the Settings Modal View Conrtoller
[self.presentingViewController dismissModalViewControllerAnimated:YES];
// Then we need to take user back to welcomeViewController
[self.navigationController pushViewController:welcomeViewController animated:YES];
它按预期关闭“设置 View ” Controller ,但导航 Controller 仍保留在“主页” View 上。没有错误,有谁知道为什么这不能正常工作?
最佳答案
通过重新排列代码解决。在 appdelegate 上搜索当前用户,然后使用主视图的根 Controller 加载导航 Controller 或运行加载欢迎 View Controller 的方法。
欢迎 View Controller 也会检查用户,如果不是当前用户,它会显示模式登录 View Controller
关于ios - UINavigationController 不推送 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12674656/