****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. text()、html() 以及 val()的区别

    text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容(包括 HTML 标记) val() - 设置或返回表单字段的值 下面的例子演示如何通过 text().htm ...

  2. DSP using MATLAB 示例 Example3.11

    用到的性质 上代码: n = -5:10; x = rand(1,length(n)); k = -100:100; w = (pi/100)*k; % freqency between -pi an ...

  3. redis 的安装

    1: redis 是什么 Redis is an open source (BSD licensed), in-memory data structure store, used as databas ...

  4. 关于JSP页面字段属性设为disabled或者readonly所带来的问题总结

    最近需要将页面一些自动求和的字段设为不可操作,当然disabled和readonly都可以实现,但是我的页面需求是来录入数据的,当用disabled时,该字段值是无法被获取并传到后台的,这时如果使用r ...

  5. 滑雪(简单dp)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 81099   Accepted: 30239 Description Mic ...

  6. virtual方法和abstract方法

    在C#的学习中,容易混淆virtual方法和abstract方法的使用,现在来讨论一下二者的区别.二者都牵涉到在派生类中与override的配合使用. 一.Virtual方法(虚方法) virtual ...

  7. 如何用distinct消除重复记录的同时又能选取多个字段值?

    http://www.cnblogs.com/warioland/archive/2012/05/30/2526128.html

  8. 后缀数组 POJ 1743 Musical Theme

    题目链接 题意:给定n个数字,求超过5个数字的,最长的,变化相同的,不相交的重复子串 分析:男人8题中的一题!数列相邻两项做差,形成新数列,即求数列中的最长重复子串(不可相交). 后缀数组+二分答案. ...

  9. MFC MSBDutyTable下载地址

    点击此处跳转到下载地址 简明教程: 对于非制表人,只需要添加空余时间-新建,然后点星期和节数有课的那个按钮,勾选自己有课的周数.全部勾好后,生成空余时间表.然后查看自己的空余时间表,并导出,发给制表人 ...

  10. TODO软件工程--如何预算项目的工期

    我的项目后台接口已经开发好,是前人留下的接口,现在只需要和前端联调,本以为后台的开发周期短,可以提早上线,可以因为旧接口不兼容新的要求 不得不重新写,造成了工期的延误. 如何计算一个工期被提上日程.