创建 UINavigationController(导航控制器)

在AppDelegate.m中创建

    // 创建一个普通控制器
RootViewController *rootVC = [[RootViewController alloc] init]; // UINavigationController主要用来管理一组控制器(至少有一个),自带 view 可是不使用
UINavigationController *rootNC = [[UINavigationController alloc] initWithRootViewController:rootVC]; // 加入 控件时 是否计算导航条的宽度 默认 YES
rootNC.navigationBar.translucent = NO; // 改变导航条的字体颜色
rootNC.navigationBar.tintColor = [UIColor blueColor]; // 改变导航条总体颜色
rootNC.navigationBar.barTintColor = [UIColor brownColor]; // 改变导航条标题颜色
rootNC.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor redColor]}; // 给整个导航条加上背景图片
[rootNC.navigationBar setBackgroundImage:[UIImage imageNamed:@"2.png"] forBarMetrics:UIBarMetricsDefault]; self.window.rootViewController = rootNC;
[rootVC release];
[rootNC release];

入栈和出栈

在 view 中设置 button 属性,并创建 button

入栈要引入后一个页面的控制器(controller)

@property (nonatomic, retain)UIButton *button;

在 controller 中绑定并实现点击事件

- (void)viewDidLoad {
[super viewDidLoad]; self.title = @"首页"; // 绑定点击事件
[self.rootView.button addTarget:self action:@selector(buttonDidClicked:) forControlEvents:UIControlEventTouchUpInside]; } #pragma mark - button 点击事件
- (void)buttonDidClicked:(UIButton *)sender
{
ScendViewController *secondVC = [[ScendViewController alloc] init];
// 压栈处理 进入下一个页面
[self.navigationController pushViewController:secondVC animated:YES];
}

出栈

#pragma mark - 实现点击事件 出栈
- (void)buttonDidClicked:(UIButton *)sender
{
[self.navigationController popViewControllerAnimated:YES]; }

指定页面跳转

#pragma mark - 通用方法 pop到指定控制器
- (void)button2DidClicked:(UIButton *)sender
{
// pop 到指定控制器
// [self.navigationController popToViewController:self.navigationController.viewControllers[0] animated:YES]; NSArray *array = self.navigationController.viewControllers; RootViewController *root = nil; for (id VC in array) {
if ([VC isKindOfClass:[RootViewController class]]) {
root = VC;
break;
}
} if (root != nil) {
[self.navigationController popToViewController:root animated:YES];
}
}

跳转到根视图控制器

- (void)buttonDidClicked:(UIButton *)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
}

自己定义返回按钮

- (void)viewDidLoad {
[super viewDidLoad];
// 定义一个返回按钮
// left and right 都能够
UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"我的返回" style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonItemAction:)]; UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonItemAction:)]; UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(leftButtonItemAction:)]; // 让系统左(右)边按钮换掉
self.navigationItem.leftBarButtonItem = leftButtonItem; }
#pragma mark - 导航栏左边按钮的点击方法
- (void)leftButtonItemAction:(UIBarButtonItem *)sender
{
[self.navigationController popViewControllerAnimated:YES];
}

UI_UINavigationController的更多相关文章

随机推荐

  1. Constructing Roads In JGShining's Kingdom(LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1025 题意:富人路与穷人路都分别有从1到n的n个点,现在要在富人点与穷人点之间修路,但是要求路不能交叉,问最多能 ...

  2. 记录一下Junit测试MongoDB,获取MongoTemplate

    只是自己记录一下,测试MongoDB帮助类时,没有配置文件的测试 public class HelperTest { MongoTemplate template; @Before public vo ...

  3. Blender插件编写指南

    前言 Blender插件是Blender的利器, 用户可以使用各种插件扩充Blender的功能. Blender Python插件以bpy.props, bpy.types.Operator, bpy ...

  4. POJ 1330 Tarjan LCA、ST表(其实可以数组模拟)

    题意:给你一棵树,求两个点的最近公共祖先. 思路:因为只有一组询问,直接数组模拟好了. (写得比较乱) 原题请戳这里 #include <cstdio> #include <bits ...

  5. 6月7号shiro

    Retains all Cache objects maintained by this cache manager :保留此缓存管理器维护的所有缓存对象 Destroyable可毁灭的 retain ...

  6. border使用

    border属性 border-width  border-style  border-color  inherit border-style的值:none  dotted(点线)  dashed(虚 ...

  7. 出现“ORA-28000:the account is locked”的解决办法

    在Oracle 11g版本中,出于安全的考虑,所有Oracle的默认用户,包括SCOTT用户都被锁定.输入用户名和口令之后,会出现错误“ORA-28000:the account is locked” ...

  8. 【Linux】swap分区简介及空间增加方式

    swap分区简介 Swap分区在系统的物理内存不够用的时候,把硬盘空间中的一部分空间释放出来,以供当前运行的程序使用.那些被释放的空间可能来自一些很长时间没有什么操作的程序,这些被释放的空间被临时保存 ...

  9. win2008系统日志不断出现【审核失败】

    win2008系统日志不断出现[审核失败] [现象] 今天查看windows日志,在  -安全-  发现不断有消息刷出,显示  -审核失败-  事件ID为4624 的记录  每分钟大概刷新8条消息(如 ...

  10. Caffe2:使用Caffe构建LSTM网络

    前言: 一般所称的LSTM网络全叫全了应该是使用LSTM单元的RNN网络. 原文:(Caffe)LSTM层分析 入门篇:理解LSTM网络 LSTM的官方简介: http://deeplearning. ...