所以我正在尝试创建一个 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];
Best Answer-推荐答案 strong>
这就是导航 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/
|