iOS 导航控制器返回栈中的某一控制器

#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 导航控制器返回栈中的某一控制器的更多相关文章
- iOS 导航栏返回到指定页面的方法和理解
关于ios中 viewcontroller的跳转问题,其中有一种方式是采用navigationController pushViewController 的方法,比如我从主页面跳转到了一级页面,又从一 ...
- 将FragmentManger事务添加到返回栈中
FragmentManger事务添加或替换的 Fragment 后,这时点击 Back 键,程序并不会返回添加之前的状态. 我们可以使用 Transaction 对象的 addToBackStack( ...
- Ios导航栏返回到指定的页面
在自己的项目实现中有这样的一个需求.一般情况下我们的导航栏返回按钮,是上个页面跳转过来,点击返回按钮返回到上来界面.但是在实际需求中有的并不是这么简单的.有的界面返回是只确定的界面.所以当时自己在实现 ...
- iOS 隐藏/去掉 导航栏返回按钮中的文字
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(, -) forBarMetrics:U ...
- iOS 导航栏返回的相关跳转
导航条跳转页面的考虑 对于用navigationcontroller来跳转页面的时候,其实是执行堆栈的进栈和出栈的操作,要想释放内存,那么在来回跳转的时候,就要考虑几个问题了 1 A =>B=& ...
- Android之Activity系列总结(二)--任务和返回栈
任务和返回栈 应用通常包含多个 Activity.每个 Activity 均应围绕用户可以执行的特定操作设计,并且能够启动其他 Activity. 例如,电子邮件应用可能有一个 Activity 显示 ...
- Android任务和返回栈完全解析,细数那些你所不知道的细节
附:Android task详解 出处:http://blog.csdn.net/guolin_blog/article/details/41087993 原文: http://developer. ...
- Android系列之Fragment(二)----Fragment的生命周期和返回栈
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- Android任务和返回栈完全解析
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/41087993 本篇文章主要内容来自于Android Doc,我翻译之后又做了些加工 ...
随机推荐
- 分布式文件系统FastDFS原理介绍
在生产中我们一般希望文件系统能帮我们解决以下问题,如:1.超大数据存储:2.数据高可用(冗余备份):3.读/写高性能:4.海量数据计算.最好还得支持多平台多语言,支持高并发. 由于单台服务器无法满足以 ...
- Linux下查找包含BOM头的文件和清除BOM头命令 2014-08-16 12:30:50
Linux下查找包含BOM头的文件和清除BOM头命令 2014-08-16 12:30:50 分类: 系统运维 查找包含BOM头的文件,命令如下: 点击(此处)折叠或打开 grep -r -I -l ...
- PHP date函数参数详解
PHP date函数参数详解 作者: 字体:[增加 减小] 类型:转载 time()在PHP中是得到一个数字,这个数字表示从1970-01-01到现在共走了多少秒,很奇怪吧 不过这样方便计 ...
- EditPlus使用心得及常用快捷键
下载好烈火版EditPlus_4.00.465_SC 然后去官网下载自动补全ACP文件 我用的是php_stx_acp.zip 解压到editplus4主目录下 然后打开软件-设置-参数 先调字 ...
- Pentium II paging mechanism
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION To understand the str ...
- 发现了一个很好的Pasical编程软件Lazarus
下载地址:http://www.lazarus.freepascal.org/ 中文社区:http://www.fpccn.com/ 该软件有几点如下特征: 1.跨平台.体积小(只有100多M) 2. ...
- mybatis 中#{}与${}的区别 (面试题)
MyBatis/Ibatis中#和$的区别 1. #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号. 如:order by #user_id#,如果传入的值是111,那么解析成sql时的 ...
- 图片放大方法、、菜单栏的位置随滚轮移动固定方法、、<a></a>去外层虚线方法:a:focus { outline:none; -moz-outline:none;};
图片放大方法一: <style type="text/css">.xt{ width:230px; height:230px;}.tp{ width:230px; he ...
- Apache的HBase与cdh的sqoop集成(不建议不同版本之间的集成)
1.修改sqoop的配资文件 2.从mysql导入到hbase(import) bin/sqoop import \ --connect jdbc:mysql://linux-hadoop3.ibei ...
- new char[]和new char()的区别
new char[1];分配一块连续的内存,也就是一个数组,里面有1个元素new char(1);分配一块内存,有一个元素,该元素被初始化为1