****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

最新文章

  1. 26、ASP.NET MVC入门到精通——后台管理区域及分离、Js压缩、css、jquery扩展
  2. 【代码笔记】iOS-给UIImageView加上圆角效果
  3. 使用虚幻引擎中的C++导论(二-UE4基类)
  4. lambda和委托
  5. 不使用synchronized和lock 锁实现线程安全单例
  6. SpringCloud Gateway 测试问题解决
  7. 使用ubuntu远程连接windows, Connect to a Windows PC from Ubuntu via Remote Desktop Connection
  8. mysql初步调试
  9. linux 安装开启SNMP协议,最下面是yum安装
  10. angular.js和ionic框架搭建一个webApp
  11. Python异常处理及元类
  12. (原创)Linux下MySQL 5.5/5.6的修改字符集编码为UTF8(彻底解决中文乱码问题)
  13. linux文件系统之loop环设备--新建一个文件系统并挂载
  14. YUV420视频上面添加字幕
  15. Cloneable 和clone的区别和联系
  16. synchronized同步方法和同步代码块的区别
  17. jdk及tomcat的安装
  18. golang sort包 排序
  19. Java 兔子问题(斐波那契数列)扩展篇
  20. 移动端使用rem时候动态设置html字体大小

热门文章

  1. DSP using MATLAB 示例Example3.4
  2. HTML元素的属性
  3. WPF ComboBox Binding
  4. Android PhoneGap 利用 Activity 实现 CordovaInterface
  5. jquery放大镜效果
  6. [WP8.1UI控件编程]Windows Phone XAML页面的编译
  7. [BZOJ2790][Poi2012]Distance
  8. 【CodeVS】 p1696 奇怪的函数
  9. Unity5.x版本AssetBundle加载研究
  10. iphone H5 input type="search" 不显示搜索 解决办法