所以我正在尝试创建一个 iphone 应用程序,并且正在尝试设置导航 Controller 。我让它从一个 View 工作到另一个 View 然后再返回。(下面的代码)有没有办法为多个 View 做到这一点?例如,从一开始就按下一个按钮切换到另一个 View ,然后按下另一个按钮转到另一个不同的 View 。我如何在不使用 Storyboard 和实际编程的情况下实现导航 Controller 工作?任何提示将不胜感激。
这是在 AppDelegate 中:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
LoginViewController *loginController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
这是其中一个 View 中的按钮方法之一:
[self.navigationController pushViewController:mainViewController animated:YES];
最佳答案
这就是导航 Controller 的作用。
您可以像这样导航到多个 View ;
To navigate from main view to secondViewController
[self.navigationController pushViewController:secondViewController animated:YES];
当前的导航栈是mainViewcontroller -> secondViewController
From second View to third View
[self.navigationController pushViewController:thirdViewController animated:YES];
当前的导航栈是mainViewcontroller -> secondViewController ->thirdViewController
To go back to previous view you can call
[self popViewControllerAnimated:YES];
关于ios - 允许在超过 2 个 View 上导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24402906/