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的更多相关文章
随机推荐
- linux下登入mysql和加压zip文件
1.类似于window中cmd登入一样 : mysql -u root -p ----> 回车 ---> 输入密码 就可以了 2. unzip abc.zip 直接进行解压 ...
- 【Python笔记】图片处理库PIL的源代码安装步骤
前段时间项目须要对某些图片打水印,用到Python的PIL库,本文以Imaging-1.1.7为例,记录PIL库的源代码编译/安装步骤. PIL全称Python Image Library.它支持多种 ...
- 如何进行js动态生成option?如何实现二级连动?
何为二级连动? 首先要明白什么是二级连动!顾名思义,就是一个动,另外一个也跟着一起动 看下面的例子: 这里有一个“市级”的选择列表框,还有一个“县级”的选择列表框,如果“市级”的选择列表框中的值发现变 ...
- iframe自适应高度的多种方法小结
转自:http://www.jb51.net/article/15780.htm 不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是 iframe的大小 ...
- iOS开发——UI篇Swift篇&UISlider
UISlider override func viewDidLoad() { super.viewDidLoad() titleLabel.text = titleString // Do any a ...
- SQL server connection KeepAlive[转]
1.什么是SQL server TCP连接的keep Alive? 简单说,keep alive 是SQL server在建立每一个TCP 连接的时候,指定了TCP 协议的keepaliveinter ...
- 乱谈Qt事件循环嵌套
本文旨在说明:QDialog::exec().QMenu::exec()等开启的局部事件循环,易用的背后,还有很多的陷阱... 引子 Qt 是事件驱动的,基本上,每一个Qt程序我们都会通过QCoreA ...
- LOVE代码收集
Love的截图函数 1 function love.load() love.filesystem.setIdentity("test") end function love.dra ...
- Advanced Awk for Sysadmins
转:http://www.linuxforu.com/2011/06/advanced-awk-for-sysadmins/ By Vishal Bhatia on June 1, 2011 in H ...
- JavaScript中数组操作
var arr1=new Array(); arr1.push(1);//在数组的中末尾添加元素,并返回新的长度 arr1.push(2);//在数组的中末尾添加元素,并返回新的长度 arr1.pop ...