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的更多相关文章
随机推荐
- HTML 转义符
特殊字符 字符 十进制 转义字符 “ " " & & & < < < > > > 不断开空格(non-breaking ...
- Android操作联系人 android开发教程
Android系统中的联系人也是通过ContentProvider来对外提供数据的,我们这里实现获取所有联系人.通过电话号码获取联系人.添加联系人.使用事务添加联系人. 获取所有联系人 1. Andr ...
- 翻译学python---《Learn Python the hard Way》---第一章 绪论
打算学习python,但是又不想单纯地看书或是写个小项目,干脆引入很流行的翻译学习法来学习吧- 在论坛上看到了国外的一本<Learn Python the hard Way> ...
- SQL Server 2008数据库重命名方法
假设SQL Server 2008中有个数据库test,现在要将其改名为zhy步骤:(1) 分离数据库:打开management studio,找到test数据库-->右键-->任务--& ...
- oc-19-成员变量修饰符
/** 成员变量修饰符 1.@public:(公开)只要导入头文件,任何位置都可以直接访问. 2.@protected:(半公开)可以在本类和子类当中进行访问.(默认) 3.@private:(私有) ...
- 高级I/O之I/O多路转接——pool、select
当从一个描述符读,然后又写到另一个描述符时,可以在下列形式的循环中使用阻塞I/O: ) if (write(STDOUT_FILENO, buf, n) != n) err_sys("wri ...
- 学java入门到精通,不得不看的15本书
学java入门到精通,不得不看的15本书 一.Java编程入门类1.<Java编程思想>2.<Agile Java>中文版 二.Java编程进阶类1.<重构 改善既有代码 ...
- 关于Android悬浮窗要获取按键响应的问题
要在Android中实现顶层的窗口弹出,一般都会用WindowsManager来实现,但是几乎所有的网站资源都是说弹出的悬浮窗不用接受任何按键响应. 而问题就是,我们有时候需要他响应按键,比如电视上的 ...
- java对象创建过程
1.jvm找到class文件路径. 2.jvm载入class文件,静态初始化,创建一个class对象. 3.为即将创建的对象分配内存空间. 4.对分配的空间进行清零,例如:int清除为0,boolea ...
- python--面向对象编程介绍
暂不考虑开发场地等复杂的东西,我们先从人物角色下手, 角色很简单,就俩个,恐怖份子.警察,他们除了角色不同,其它基本都 一样,每个人都有生命值.武器等. 咱们先用非OOP的方式写出游戏的基本角色 引子 ...