#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. json解析json字符串时候,数组必须对应jsonObjectArray,不能对应JsonObject。否则会解析错误。

    json第三方解析json字符串时候,json数组必须对应jsonObjectArray,不能对应JsonObject.->只要是[]开头的都是json数组字符串,就要用jsonArray解析 ...

  2. 有两个地方,用到了javabean对象和属性字符串值之间的转换

    1.有两个地方,用到了javabean对象和属性字符串值之间的转换 2.一个是接入层spring mvc,将json字符串参数转换为javaBean.通过@RequestBody javaBean方式 ...

  3. SSH服务器拒绝了密码 请再试一次

    应该是sshd的设置不允许root用户用密码远程登录. 修改: vim /etc/ssh/sshd_config 找到: # Authentication:LoginGraceTime 120Perm ...

  4. 送给使用phpstorm+thinkphp开发者的福利

    送给使用phpstorm+thinkphp开发者的福利   记得两年前的这个时候,我开始学习php.我选择了thinkphp入门,写了我的第一个简单的cms.当时我什么都不懂,但是这里的技术氛围好的, ...

  5. php获得网站根目录的几个方法

    php获得网站根目录的几个方法 电脑软硬件应用网 45IT.COM 时间:2015-01-08 12:54 作者:佚名 在php中我们要得到网站根目录可以用很多全局变量实现了,如可以利用__file_ ...

  6. Bootstrap页面布局17 - BS选项卡

    代码结构: <div class='container-fluid'> <h2 class='page-header'>Bootstrap 选项卡</h2> < ...

  7. JavaScript函数参数与调用

    函数调用: /* 1. 函数调用 */ ,,,); /* 2. 方法调用 */ this.CName = "全局"; var o = { CName:"o类", ...

  8. ASP.Net网站程序在编译发布部署后的后期修改

    ASP.Net网站程序在发布部署后的后期修改 作者:东篱南山 这里说的后期修改是指网站编译发布并部署好之后,对程序进行的修改,即在不能更改现有代码的情况下,更改页面的显示或是更改业务逻辑.一般是在程序 ...

  9. jstl标签库基础教程及其使用代码(一)。

    概述 在 JSP 页面中,使用标签库代替传统的 Java 片段语言来实现页面的显示逻辑已经不是新技术了,然而,由自定义标签很容易造成重复定义和非标准的实现.鉴于此,出现了 JSTL ( JSP Sta ...

  10. golang AES/ECB/PKCS5 加密解密 url-safe-base64

    因为项目的需要用到golang的一种特殊的加密解密算法AES/ECB/PKCS5,但是算法并没有包含在标准库中,经过多次失败的尝试,终于解码成功,特此分享: /* 描述 : golang AES/EC ...