****HMAppDelegate.m

@implementation HMAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; HMOneViewController *oneVc = [[HMOneViewController alloc] init]; UINavigationController *navVc = [[UINavigationController alloc] initWithRootViewController:oneVc]; self.window.rootViewController = navVc; [self.window makeKeyAndVisible];
return YES;
} -(void)test1{
//1.创建一个导航控制器
//UINavigationController *navVc = [[UINavigationController alloc] init]; //2.设置导航控制器的子控制器
UIViewController *oneVc = [[UIViewController alloc] init];
oneVc.view.backgroundColor = [UIColor grayColor]; UIViewController *twoVc = [[UIViewController alloc] init];
twoVc.view.backgroundColor = [UIColor purpleColor]; //method 1 : 添加导航控制器的子控制器
//[navVc pushViewController:oneVc animated:YES];
//[navVc pushViewController:twoVc animated:YES]; //method 2
//navVc.viewControllers = @[oneVc]; //method 3
// [navVc addChildViewController:oneVc];
// [navVc addChildViewController:twoVc]; //self.window.rootViewController = navVc; }

******HMOneViewController.m

#import "HMOneViewController.h"
#import "HMTwoViewController.h" @interface HMOneViewController ()
- (IBAction)jumpTwoVc:(id)sender; @end @implementation HMOneViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//NSLog(@"%@",self.navigationController.viewControllers); //设置导航栏的内容
//设置标题
self.navigationItem.title = @"第一个控制器"; //设置导航栏左边的按钮
UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:nil action:nil];
self.navigationItem.leftBarButtonItem = leftBtn; //设置下一个控制器的返回按钮
//当前控制的navigationItem里的返回按钮是决定下一个控制器的返回按钮
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} //跳到第二个控制器
- (IBAction)jumpTwoVc:(id)sender { HMTwoViewController *twoVc = [[HMTwoViewController alloc] init]; NSLog(@"%@",self.navigationController);
[self.navigationController pushViewController:twoVc animated:YES];
}
@end

*******HMTwoViewController.m

#import "HMTwoViewController.h"
#import "HMThreeViewController.h" @interface HMTwoViewController () - (IBAction)backOneVc:(id)sender; - (IBAction)jumpThreeVc; @end @implementation HMTwoViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//NSLog(@"%@",self.navigationController.viewControllers); //设置标题
self.navigationItem.title = @"第二个控制器"; //设置返回按钮
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"BACK" style:UIBarButtonItemStylePlain target:nil action:nil]; //设置导航栏左边的按钮
//如果设置leftBarButtonItem ,之前那个返回无效
UIBarButtonItem *leftBtnItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(back)];
self.navigationItem.leftBarButtonItem = leftBtnItem; //设置导航栏右边的按钮
UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:nil action:nil];
//self.navigationItem.rightBarButtonItem = search; UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:nil action:nil]; self.navigationItem.rightBarButtonItems = @[search,refresh]; } //返回上一个控制器
-(void)back{
[self.navigationController popViewControllerAnimated:YES];
} - (IBAction)backOneVc:(id)sender { [self.navigationController popViewControllerAnimated:YES];
} - (IBAction)jumpThreeVc { //跳到第三个控制器
HMThreeViewController *threeVc = [[HMThreeViewController alloc] init];
[self.navigationController pushViewController:threeVc animated:YES];
}
@end

********HMThreeViewController.m

#import "HMThreeViewController.h"

@interface HMThreeViewController ()
- (IBAction)backOneVc:(id)sender; @end @implementation HMThreeViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib. //栈的所有控制器
NSLog(@"%@",self.navigationController.viewControllers);
NSArray *array = [self.navigationController childViewControllers];
NSLog(@"%@",array); //设置标题View
UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd]; self.navigationItem.titleView = btn; //设置返回按钮btn_back_normal
UIButton *redBtn = [UIButton buttonWithType:UIButtonTypeCustom];
redBtn.bounds = CGRectMake(, , , );
[redBtn setBackgroundImage:[UIImage imageNamed:@"btn_back_normal"] forState:UIControlStateNormal]; [redBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *redBackBtnItem = [[UIBarButtonItem alloc] initWithCustomView:redBtn]; self.navigationItem.leftBarButtonItem = redBackBtnItem; } //返回上一个控制咕噜
-(void)back{ [self.navigationController popViewControllerAnimated:YES]; } - (IBAction)backOneVc:(id)sender { //返回第一个控制器
//[self.navigationController popToRootViewControllerAnimated:YES];
//获取第一个控制器
UIViewController *oneVC = self.navigationController.viewControllers[];
//返回指定控制器
[self.navigationController popToViewController:oneVC animated:YES];
}
@end

IOS第12天(2,UINavigationController导航控制器)的更多相关文章

  1. UINavigationController导航控制器

    UINavigationController导航控制器,是多个界面间跳转的重要元素,可以理解为它存储着多个viewController,它的存储结构是栈,栈的特点是先进后出,所以添加视图控制器时,要特 ...

  2. UINavigationController 导航控制器 ,根据文档写的一些东西

    今天讲了导航控制器UINavigationController 和标签栏视图控制器UITabBarController 先来说一说导航视图控制器  UINavigationController 导航控 ...

  3. IOS UINavigationController 导航控制器

    /** 导航控制器掌握: 1.创建导航控制器 UINavigationController *nav = [[UINavigationController alloc] initWithRootVie ...

  4. 【iOS开发-21】UINavigationController导航控制器初始化,导航控制器栈的push和pop跳转理解

    (1)导航控制器初始化的时候一般都有一个根视图控制器,导航控制器相当于一个栈,里面装的是视图控制器,最先进去的在最以下,最后进去的在最上面.在最上面的那个视图控制器的视图就是这个导航控制器对外展示的界 ...

  5. iOS开发 — (UINaVigationController)导航控制器,界面传值

    UINavigationController 继承于 UIViewController , 以栈的方式管理所 控制的视图控制器 . 至少要有一个被管理的视图控制器 ,这个控制器我们称作导航控制器的根视 ...

  6. UINavigationController导航控制器初始化 导航控制器栈的push和pop跳转理解

    (1)导航控制器初始化的时候一般都有一个根视图控制器,导航控制器相当于一个栈,里面装的是视图控制器,最先进去的在最下面,最后进去的在最上面.在最上面的那个视图控制器的视图就是这个导航控制器对外展示的界 ...

  7. IOS开发之功能模块--自定义导航控制器类常用自定义的代码

    前言:本文篇幅不多,但是涉及到的内容却是开发中常用的. 涉及的内容: 1.统一设置导航控制器子控制器的返回按钮. 2.因为修改了系统的返回按钮,所以还需要设置手势事件. 3.隐藏底部的工具条. 这里直 ...

  8. 轻量级应用开发之(10) UINavigationController导航控制器

    一 多控制器 1)一个iOS的app很少只由一个控制器组成,除非这个app极其简单2)当app中有多个控制器的时候,我们就需要对这些控制器进行管理3)有多个view时,可以用一个大的view去管理1个 ...

  9. iOS边练边学--UINavigationController导航条的使用

    一.使用UINavigationController的步骤以及代码 // 程序加载完成后执行的代码 - (BOOL)application:(UIApplication *)application d ...

随机推荐

  1. POJ 1159 回文串-LCS

    题目链接:http://poj.org/problem?id=1159 题意:给定一个长度为N的字符串.问你最少要添加多少个字符才能使它变成回文串. 思路:最少要添加的字符个数=原串长度-原串最长回文 ...

  2. mvc-6依赖管理

    CommonJS CommonJS规范,主要解决命名空间管理模块和用一套标准的编程模式来加载模块: 很快成为了JavaScript模块写法的事实标准: 它包含IO接口,底层的套接字流,以及单元测试等标 ...

  3. Java 程序员们值得一看的好书推荐[转载]

    “学习的最好途径就是看书“,这是我自己学习并且小有了一定的积累之后的第一体会.个人认为看书有两点好处: 能出版出来的书一定是经过反复的思考.雕琢和审核的,因此从专业性的角度来说,一本好书的价值远超其他 ...

  4. 【noip2014T3】

    上文有提到noip2014还有没A的嘛..就先把这个坑给填了 flappy bird好sad啊 还是先做解方程 八中的数据好强了,然而我最后凑了四个质数就A了,感谢shy! 作为联赛最后一题,学习它的 ...

  5. ural 1251. Cemetery Manager

    1251. Cemetery Manager Time limit: 1.0 secondMemory limit: 64 MB There is a tradition at the USU cha ...

  6. SQL: See the TSQL underneath the sp_execute calls

    When use SQL Server Profiler, on the Events Selection tab, check Show all events; Find the Store Pro ...

  7. HDU5823 : color II

    每种颜色的点集肯定是独立集,因此可以通过$O(2^n)$枚举每个集合判断出每个集合是否只需要一种颜色即可染色. 设$f[i][S]$表示$i$种颜色覆盖$S$这个集合的方案数,假定两个集合可以相交,那 ...

  8. ACM: 强化训练-Roads in the North-BFS-树的直径裸题

    Roads in the North Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu De ...

  9. RSA_RSA算法原理(一)

    如果你问我,哪一种算法最重要?我可能会回答"公钥加密算法". 因为它是计算机通信安全的基石,保证了加密数据不会被破解.你可以想象一下,信用卡交易被破解的后果. 进入正题之前,我先简 ...

  10. 纪念逝去的岁月——C/C++交换排序

    交换排序 代码 #include <stdio.h> void printList(int iList[], int iLen) { ; ; i < iLen; i++) { pri ...