//
// FourthViewController.h
// UI1_UINavigationController
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface FourthViewController : UIViewController @end //
// FourthViewController.m
// UI1_UINavigationController
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "FourthViewController.h" @interface FourthViewController () @end @implementation FourthViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor purpleColor];
//视图控制器数组
NSInteger count = [self.navigationController.viewControllers count];
NSLog(@"count = %li", count); UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
btn1.frame = CGRectMake(100, 100, self.view.frame.size.width-200, 50);
[btn1 setTitle:@"popToFirst" forState:UIControlStateNormal];
btn1.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn1.tag = 100;
[self.view addSubview:btn1]; UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
btn2.frame = CGRectMake(100, 200, self.view.frame.size.width-200, 50);
[btn2 setTitle:@"popToSecond" forState:UIControlStateNormal];
btn2.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[btn2 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn2.tag = 101;
[self.view addSubview:btn2];
} - (void)btnClicked:(UIButton *)btn
{
if (btn.tag==100) {
//直接切换到根视图控制器
[self.navigationController popToRootViewControllerAnimated:YES];
}
else if (btn.tag==101)
{
//获取指定位置的视图控制器
//视图控制器必须存在
UIViewController *controller = [self.navigationController.viewControllers objectAtIndex:1];
[self.navigationController popToViewController:controller animated:YES];
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// ThirdViewController.h
// UI1_UINavigationController
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ThirdViewController : UIViewController @end //
// ThirdViewController.m
// UI1_UINavigationController
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ThirdViewController.h"
#import "FourthViewController.h" @interface ThirdViewController () @end @implementation ThirdViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100,200, self.view.frame.size.width-200, 50);
[btn setTitle:@"pushToFourth" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[self.view addSubview:btn]; NSLog(@"count = %li", self.navigationController.viewControllers.count);
} - (void)btnClicked
{
FourthViewController *fvc = [[FourthViewController alloc] init];
[self.navigationController pushViewController:fvc animated:YES]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// SecondViewController.h
// UI1_UINavigationController
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface SecondViewController : UIViewController @end //
// SecondViewController.m
// UI1_UINavigationController
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SecondViewController.h"
#import "ThirdViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
btn1.frame = CGRectMake(100, 100, self.view.frame.size.width-200, 50);
[btn1 setTitle:@"pushToThird" forState:UIControlStateNormal];
btn1.titleLabel.font = [UIFont boldSystemFontOfSize:23];
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn1.tag = 100;
[self.view addSubview:btn1]; UIButton *btn2= [UIButton buttonWithType:UIButtonTypeSystem];
btn2.frame = CGRectMake(100, 300, self.view.frame.size.width-200, 50);
[btn2 setTitle:@"popToFirst" forState:UIControlStateNormal];
btn2.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[btn2 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn2.tag = 101;
[self.view addSubview:btn2];
} - (void)btnClicked:(UIButton *)btn
{
//压栈
if (btn.tag == 100) {
ThirdViewController *tvc = [[ThirdViewController alloc] init];
[self.navigationController pushViewController:tvc animated:YES];
}
else if(btn.tag == 101)
{
//出栈
//栈顶的视图控制器出栈
[self.navigationController popViewControllerAnimated:YES];
} }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// AppDelegate.m
// UI1_UINavigationController
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch
//创建导航控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.window.rootViewController];
self.window.rootViewController = nav;
return YES;
}
//
// ViewController.m
// UI1_UINavigationController
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "SecondViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor cyanColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 200, self.view.frame.size.width-200, 50);
[btn setTitle:@"push" forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:24]; [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
} - (void)btnClicked
{
SecondViewController *svc = [[SecondViewController alloc] init];
//取得导航控制器对象
//视图控制器必须被添加到导航控制器中
//把视图控制器压栈到导航控制器中
[self.navigationController pushViewController:svc animated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UI1_UINavigationController的更多相关文章

随机推荐

  1. char.js专门用来做数据统计图

    <canvas id="cashback" width="930" height="460"></canvas>&l ...

  2. Android 图像压缩,和LRU算法使用的推荐链接

    近两日,看的关于这些方面的一些教程数十篇,最好的当属google原版的教程了.国内有不少文章是翻译这个链接的. 需要注意的一点是:Android的SDK中的LRU算法在V4包和Util包中各有一个,推 ...

  3. 【JavsScript】作用域链

    阿里巴巴广招前端.Java.测试.算法人才,只要你有一技之长,精通于某项领域,无学历要求,都可以来试试,有兴趣的联系luyong.sunly@alibaba-inc.com

  4. 0c-37-ARC

    .什么是ARC? Automatic Reference Counting,自动引用计数,即ARC,可以说是WWDC2011和iOS5所引入的最大的变革和最激动人心的变化.ARC是新的LLVM .0编 ...

  5. C#中listbox中选中多项,并删除

    1.SelectionMode 改成可以多选2.利用KeyDown事件: private void listBox1_KeyDown(object sender, KeyEventArgs e) { ...

  6. Linux下安装FTP

    1.查询进程是否有ftp服务 ps -ef|grep vsftpd 查询是否安装vsftpd: rpm -qa |grep vsftpd (rpm的安装:apt-get install rpm) 2. ...

  7. 优化 App 的启动速度

    App 的启动速度不仅影响我们调试,也直接关系到用户体验.之前有些很久没有打开过的项目,需要花费很长的时间才完成编译:对应的 App 在点击后,许久才出现启动画面.你是否为这些问题苦恼过呢? 这是我观 ...

  8. Windows配置端口转发

    windows命令行下用netsh实现端口转发 微软Windows的netsh是一个命令行脚本实用工具.使用netsh工具 ,可以查看或更改本地计算机或远程计算机的网络配置.不仅可以在本地计算机上运行 ...

  9. 巧用FileShare解决C#读写文件时文件正由另一进程使用的bug

    在使用C#进行文件读写的时候,一旦对文件操作频繁,总会碰到一些令人措手不及的意外.例如经常会碰到的一个问题: System.IO.IOException: 文件“XXX”正由另一进程使用,因此该进程无 ...

  10. 【Android Api 翻译2】Android Testing(1) 浅尝Android测试的奥秘

    ------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 仅供学习和交流使用,翻译不好勿喷,请只摘除不合适的地方 Testing The Android fram ...