#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. 解决Eclipse Debug 的source not found问题

    最近在做Android 4.4系统的定制开发(RockIII)进行Debug时,并打上断点,运行到断点处时,Debug窗口出现source not found问题(没有自动关联程序编码): 解决办法: ...

  2. PHP面向对象程序设计的61条黄金法则

    PHP面向对象程序设计的61条黄金法则   你不必严格遵守这些原则,违背它们也不会被处以宗教刑罚.但你应当把这些原则看成警铃,若违背了其中的一条,那么警铃就会响起 . ----- Arthur J.R ...

  3. 在Delphi下,如何使ShowMessage中的按钮中文化

    如果你使用messagedlg(对showmessage也适用)可以汉化定义按钮caption的常量,具体操作步骤如下: 1.   打开文件consts.pas(在Delphi安装目录的/source ...

  4. Delphi 中的结构体与结构体指针

    好多程序都给结构体变量设定了一个结构体指针 例如: PAbc = ^TAbc; TAbc = record a: string[10]; b: string[5]; c: string[1]; end ...

  5. BAE3.0上的java+tomcat代码发布

    ---------------------------------2016/01/25更新-------------------------------------- 最近两天去百度开放云,发现它再也 ...

  6. forms6 builder安装之后设置注册表开发环境

  7. Python中布尔类型

    我们已经了解了Python支持布尔类型的数据,布尔类型只有True和False两种值,但是布尔类型有以下几种运算:与运算:只有两个布尔值都为 True 时,计算结果才为 True.True and T ...

  8. Qt 之 自定义提示信息框—迅雷风格(模拟QDialog类的exec()方法) good

    http://blog.csdn.net/goforwardtostep/article/details/53614830

  9. C# Dictionary几种遍历方式

    class Program { static void Main(string[] args) { Dictionary<string, string> myDictionary = ne ...

  10. 有关sass

    一.sass编译为css文件 编译的方法有很多 1.koala编译  请参考 http://www.w3cplus.com/blog/777.html http://koala-app.com/ind ...