首页 > 代码库 > 导航视图(四)
导航视图(四)
导航视图
1、创建导航视图根视图:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; ViewController* viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; self.window.rootViewController = self.navigationController; [self.window makeKeyAndVisible]; return YES; }
2、跳转到新视图控制器:
SecondViewController* secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; [self.navigationController pushViewController:secondView animated:nil];
3、返回之前的视图控制器:
//回到上一级视图 // [self.navigationController popViewControllerAnimated:YES]; //回到根视图 // [self.navigationController popToRootViewControllerAnimated:YES]; //回到指定视图 NSArray * ctrlArray = self.navigationController.viewControllers; [self.navigationController popToViewController:[ctrlArray objectAtIndex:0] animated:YES];
备注:这里各个压入堆栈中的ViewController 都采用self.navigationController获取导航控制器。可参考下文:
http://kingbinchow.iteye.com/blog/1990807
导航视图(四)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。