#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
#import "AppDelegate.h"
#import "FirstViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (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];
//初始化控制器
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:[[FirstViewController alloc] init]];
self.window.rootViewController = navi; [self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController

@end
#import "FirstViewController.h"
#import "SecondViewController.h"
@interface FirstViewController () @end @implementation FirstViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
self.title = @"第一个控制器"; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(, , , );
button.backgroundColor = [UIColor whiteColor];
[button setTitle:@"跳到第二个控制器" forState:];
[button setTitleColor:[UIColor greenColor] forState:];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
} - (void)buttonAction:(UIButton *)sender{
[self.navigationController pushViewController:[[SecondViewController alloc] init] animated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController

@end
#import "SecondViewController.h"
#import "ThirdViewController.h"
@interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor orangeColor];
self.title = @"第二个控制器"; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(, , , );
button.backgroundColor = [UIColor whiteColor];
[button setTitle:@"跳到第三个控制器" forState:];
[button setTitleColor:[UIColor greenColor] forState:];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
} - (void)buttonAction:(UIButton *)sender{
[self.navigationController pushViewController:[[ThirdViewController alloc] init] animated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import <UIKit/UIKit.h>

@interface ThirdViewController : UIViewController

@end
#import "ThirdViewController.h"
#import "FourthViewController.h" @interface ThirdViewController () @end @implementation ThirdViewController - (void)viewDidLoad {
[super viewDidLoad];
self.title = @"第三个控制器";
self.view.backgroundColor = [UIColor yellowColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(, , , );
button.backgroundColor = [UIColor whiteColor];
[button setTitle:@"跳到第四个控制器" forState:];
[button setTitleColor:[UIColor greenColor] forState:];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
} - (void)buttonAction:(UIButton *)sender{
[self.navigationController pushViewController:[[FourthViewController alloc] init] animated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import <UIKit/UIKit.h>

@interface FourthViewController : UIViewController

@end
#import "FourthViewController.h"
#import "FifthViewController.h"
@interface FourthViewController () @end @implementation FourthViewController - (void)viewDidLoad {
[super viewDidLoad];
self.title = @"第四个控制器";
self.view.backgroundColor = [UIColor greenColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(, , , );
button.backgroundColor = [UIColor whiteColor];
[button setTitle:@"跳到第五个控制器" forState:];
[button setTitleColor:[UIColor greenColor] forState:];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button]; } - (void)buttonAction:(UIButton *)sender{
[self.navigationController pushViewController:[[FifthViewController alloc] init] animated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
#import <UIKit/UIKit.h>

@interface FifthViewController : UIViewController

@end
#import "FifthViewController.h"
#import "ThirdViewController.h"
@interface FifthViewController () @end @implementation FifthViewController - (void)viewDidLoad {
[super viewDidLoad];
self.title = @"第五个控制器";
self.view.backgroundColor = [UIColor blueColor];
[self setupViews];
}
/**
* 初始化视图
*/
- (void)setupViews{
[self initializeButtonWithFrame:CGRectMake(, , , ) tag: title:@"返回第一个控制器"];
[self initializeButtonWithFrame:CGRectMake(, , , ) tag: title:@"返回第二个控制器"];
[self initializeButtonWithFrame:CGRectMake(, , , ) tag: title:@"返回第三个控制器"];
[self initializeButtonWithFrame:CGRectMake(, , , ) tag: title:@"返回第四个控制器"];
}
/**
* 初始化button
*
* @param frame 尺寸
* @param tag 标签
* @param title button的标题
*/
- (void)initializeButtonWithFrame:(CGRect)frame tag:(NSInteger)tag title:(NSString *)title {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame =frame;
button.tag = tag;
button.backgroundColor = [UIColor orangeColor];
[button setTitle:title forState:];
[button setTitleColor:[UIColor whiteColor] forState:];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
/**
* button触发的事件
*/
- (void)buttonAction:(UIButton *)sender{
// 在self.navigationController.viewControllers数组(的栈)中找到相应的控制器
UIViewController *viewController = self.navigationController.viewControllers[sender.tag - ];
[self.navigationController popToViewController:viewController animated:YES]; //跳到某一控制器
//遍历导航控制器(栈)中的控制器
// for (UIViewController *controller in self.navigationController.viewControllers) {
// // 找到相应的控制器
// if ([controller isKindOfClass:[ThirdViewController class]]) {
// //跳转到该控制器
// [self.navigationController popToViewController:controller animated:YES];
// }
// }
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

iOS 导航控制器返回栈中的某一控制器的更多相关文章

  1. iOS 导航栏返回到指定页面的方法和理解

    关于ios中 viewcontroller的跳转问题,其中有一种方式是采用navigationController pushViewController 的方法,比如我从主页面跳转到了一级页面,又从一 ...

  2. 将FragmentManger事务添加到返回栈中

    FragmentManger事务添加或替换的 Fragment 后,这时点击 Back 键,程序并不会返回添加之前的状态. 我们可以使用 Transaction 对象的 addToBackStack( ...

  3. Ios导航栏返回到指定的页面

    在自己的项目实现中有这样的一个需求.一般情况下我们的导航栏返回按钮,是上个页面跳转过来,点击返回按钮返回到上来界面.但是在实际需求中有的并不是这么简单的.有的界面返回是只确定的界面.所以当时自己在实现 ...

  4. iOS 隐藏/去掉 导航栏返回按钮中的文字

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(, -) forBarMetrics:U ...

  5. iOS 导航栏返回的相关跳转

    导航条跳转页面的考虑 对于用navigationcontroller来跳转页面的时候,其实是执行堆栈的进栈和出栈的操作,要想释放内存,那么在来回跳转的时候,就要考虑几个问题了 1 A =>B=& ...

  6. Android之Activity系列总结(二)--任务和返回栈

    任务和返回栈 应用通常包含多个 Activity.每个 Activity 均应围绕用户可以执行的特定操作设计,并且能够启动其他 Activity. 例如,电子邮件应用可能有一个 Activity 显示 ...

  7. Android任务和返回栈完全解析,细数那些你所不知道的细节

    附:Android  task详解 出处:http://blog.csdn.net/guolin_blog/article/details/41087993 原文: http://developer. ...

  8. Android系列之Fragment(二)----Fragment的生命周期和返回栈

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  9. Android任务和返回栈完全解析

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/41087993 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工 ...

随机推荐

  1. Shader Model 3.0:Using Vertex Textures SM3:使用顶点纹理 (NVIDIA spec, 6800支持使用D3DFMT_R32F and D3DFMT_A32B32G32R32F的纹理格式实现Vertex Texture。)

    翻译者 周波 zhoubo22@hotmail.com 版权所有 Philipp Gerasimov Randima (Randy) Fernando Simon Green NVIDIA Corpo ...

  2. Mininet实验 基于Mininet实现BGP路径挟持攻击实验

    参考:基于Mininet实现BGP路径挟持攻击实验 实验目的: 掌握如何mininet内模拟AS. 掌握BGP路径挟持的原理和分析过程. 实验原理: 互联网是由相互连接的自治系统AS组成的,通过一个通 ...

  3. select * 所有字段时如何巧妙的使用覆盖索引

    内容从"mysql高性能书籍"  179页摘取 当select * 时.往往使用不到索引..效率不高,因为查询从表中选择所有的列,没有任何索引能覆盖所有的列.不过还是有捷径可以利用 ...

  4. 用thinkphp进行微信开发的整体设计思考

    用thinkphp进行微信开发的整体设计思考 http://www.2cto.com/weixin/201504/388423.html 2015-04-09      0个评论       作者:明 ...

  5. Yii源码阅读笔记(十八)

    View中的查找视图文件方法和渲染文件方法 /** * Finds the view file based on the given view name. * 通过view文件名查找view文件 * ...

  6. Memcache 提高缓存命中率

    最近手上某个项目跟新代码,新的代码里大量采用memcahce作为缓存.所以开始深入了解memcache的内存分配策略.以前就听说有个PHP写的memcache监控脚本,在网上搜索了一下,果断下载下来用 ...

  7. UBUNTU 14.04 安装 OPENCV 2.4.9

    1.  从OpenCV.org 下载源代码 opencv-2.4.9.zip 2. 解压到准备好的目录 unzip opencv-2.4.9.zip 3. 进入源码目录,创建release目录 cd ...

  8. docker jenkins

    https://segmentfault.com/a/1190000003732967

  9. 关于网站的UV分析

    一:准备 1.统计的维度 guid tracktime provice 2.key与value的设定 key:date+provice_guid value:NullWritable 3.案例分析 表 ...

  10. Unicode与UTF8相互转化(使用MultiByteToWideChar)

    1.简述 最近在发送网络请求时遇到了中文字符乱码的问题,在代码中调试字符正常,用抓包工具抓的包中文字符显示正常,就是发送到服务器就显示乱码了,那就要将客户端和服务器设置统一的编码(UTF-8),而我们 ...