UI1_UINavigationController
//
// 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的更多相关文章
随机推荐
- 【JavaScript】深入理解JavaScript之强大的原型和原型链
由于JavaScript是唯一一个被广泛使用的基于原型继承的语言,所以理解两种继承模式的差异是需要一定时间的,今天我们就来了解一下原型和原型链. AD: hasOwnProperty函数: hasOw ...
- Quartz表达式
“*”字符代表所有可能的值 因此,“*”在子表达式(月)里表示每个月的含义,“*”在子表达式(天(星期))表示星期的每一天 “/”字符用来指定数值的增量 例如:在子表达式(分钟)里的“0/15”表示从 ...
- purge
RR级别 mysql V5.6 debug ; 测试1 会话1: mysql)); Query OK, rows affected (0.04 sec) mysql,"a"); Q ...
- c#如何在win7下设置IE代理的完美解决方案
有人还发现:在window7下, 在一个进程中, 设置和取消不能都执行,---- 要么设置,要么取消. 但如果第一次运行时,只进行设置代理,退出后再进运行,只进行取消,这是没有问题的. 简单说说中医 ...
- zookeeper的异常处理(Disconnected, SyncConnected, Expired)
最近系统中使用zookeeper支持三个功能:全量/增量索引的消息通知:搜索活跃节点检查:分布式锁做索引切换同步. 线上服务对稳定性要求较高,包括各种异常情况,如网络中断导致连接断开,系统load过高 ...
- linux上一些命令
ps -ef看看有没有tomcat的进程:也可以用netstat -tnl来看tomcat的端口是否开放
- 适配iOS9遇到的一些问题_Scheme白名单_ Bitcode及解决办法
升级Xcode7 运行项目发现报错如下: 1.Scheme白名单问题 -canOpenURL: failed for URL: “weixin://app/wxdaae92a9cfe5d54c/” - ...
- Struts2+hibernate3+Spring2的整合方法
浅谈Struts+hibernate+Spring的整合方法 摘要:本文将介绍Struts,Spring与hibernate的集成.希望大家能从中受用. 1.在工程中导入spring支持,导入的Jar ...
- Solr的检索运算符 (转载)
1. “:” 指定字段查指定值,如返回所有值*:*2. “?” 表示单个任意字符的通配3. “*” 表示多个任意字符的通配(不能在检索的项开始使用*或者?符号)4. “~” 表示模糊检索,如检索拼写类 ...
- [JavaEE] WEB-INF有关的目录路径总结
1.资源文件只能放在WebContent下面,如 CSS,JS,image等.放在WEB-INF下引用不了. 2.页面放在WEB-INF目录下面,这样可以限制访问,提高安全性.如JSP,html 3. ...