首先, 先创建三个VC.

完毕点击按钮, 进入下一页, 并可以返回.

要先把导航视图控制器创建出来.

在AppDelegate.m 文件里代码例如以下:

#import "AppDelegate.h"
#import "MainViewController.h"
@interface AppDelegate ()
@end @implementation AppDelegate
- (void)dealloc{
[_window release];
[super dealloc];
}
- (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];
[self.window makeKeyAndVisible];
[_window release]; //先创建一个ViewController
MainViewController *mainVC = [[MainViewController alloc] init];
//创建导航视图控制器
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:mainVC];
self.window.rootViewController = navC;
//释放
[mainVC release];
[navC release]; return YES;
}

对于导航视图控制器的一些设置.

  //导航视图控制器的高度是44,上面的状态栏高度是20,加在一起默认是64;
// 加上一个标题.
self.title = @"猫眼电影";
// 对外观进行设置,不是全部的颜色都是BackgroundColor;
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
  // 创建一个UIView
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor = [UIColor orangeColor];
[self.view addSubview:view];
[view release];
// 为了防止坐标系被篡改,我们把bar从半透明改为全透明.这样坐标系的原点会自己主动向下推64
self.navigationController.navigationBar.translucent = NO;

内容方面的设置


//另外一种标题的设置
self.navigationItem.title = @"骨头 商店"; // 指定一些视图,作为titleView
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"信息",@"通话"]];
self.navigationItem.titleView = seg;
[seg release];

创建左右两个按钮

    //左按钮
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemOrganize target:self action:@selector(leftAction:)] autorelease]; //右按钮
//如此创建,原本拖拽的图标的颜色是黄色,但这么创建后,图标是蓝色的.
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"狗.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)] autorelease]; // 以下方法图标将会显示黄色.
// 创建一个小button,把图片装上.
UIButton *Littlebutton = [UIButton buttonWithType:UIButtonTypeCustom];
Littlebutton.frame = CGRectMake(0, 0, 40, 40);
[Littlebutton setImage:[UIImage imageNamed:@"狗.png"] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:Littlebutton]; UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(260, 530, 80, 40);
button.backgroundColor = [UIColor yellowColor];
[self.view addSubview:button];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
button.layer.cornerRadius = 10;
[button setTitle:@"下一页" forState:UIControlStateNormal];

对应的, 左右两个按钮的点击事件也要实现

- (void)rightAction:(UIBarButtonItem *)button{
} - (void)leftAction:(UIBarButtonItem *)barButton{
}

点击Button跳转到下一页.

用模态也可以跳转 , 可是跳转的页面不再有导航视图.

实现Button的点击事件

当中我要完毕从前向后传值.

- (void)click:(UIButton *)button{
- // 用导航视图控制器跳转.
//1.先创建下一页对象.
SecondViewController *secondVC = [[SecondViewController alloc] init];
//通过导航控制器找到
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release]; // 属性传值第二步
secondVC.number = 100;
secondVC.string = self.textField.text;
secondVC.arr = @[@"haha",@"啦啦"];
}

第二个页面的 .h 中代码:

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController
// 属性传值第一步,在第二个页面写一条属性.
@property(nonatomic, assign)NSInteger number; //属性传值另外一种: 针对TextField中的字符串写一条属性.
@property(nonatomic, copy)NSString *string; //属性传值第三种: 传一个数组
@property(nonatomic, retain)NSArray *arr; @end

第二个页面的 .m 中代码:

#import "SecondViewController.h"
#import "ThirdViewController.h"
@interface SecondViewController ()
@property(nonatomic, retain)UILabel *label;
@end @implementation SecondViewController
- (void)dealloc{
[_label release];
[_string release];
[_arr release];
[super dealloc];
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
self.navigationController.navigationBar.barTintColor = [UIColor magentaColor]; UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(260, 530, 80, 40);
button.backgroundColor = [UIColor blueColor];
[self.view addSubview:button];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
button.layer.cornerRadius = 10;
[button setTitle:@"下一页" forState:UIControlStateNormal]; //第三步:
//第一种:
NSLog(@"%ld",self.number); //另外一种:
self.label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
[self.view addSubview:self.label];
[_label release];
self.label.layer.borderWidth = 1; //属性传值第三步:里面的值赋给label
self.label.text = self.string;
// 第三种:
NSLog(@"%@",self.arr[1]);
}
- (void)click:(UIButton *)button{
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
[self.navigationController pushViewController:thirdVC animated:YES];
[thirdVC release];
}

属性传值. 传NSIntger . NSString . NSArray

UI 07 _ 导航视图控制器 与 属性传值的更多相关文章

  1. Snail—UI学习之导航视图控制器UINavigationController(系统)

    背景 有一个根视图控制器 然后跳转到第一个界面  第一个界面能够返回到根视图 也能够跳转到第二个视图 第二个视图能够直接返回到根视图 新建三个ViewController    RootViewCon ...

  2. ios 导航视图控制器 跳转

    import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...

  3. 步步入佳境---UI入门(3) --单视图控制器

    视图控制器特点//1,抽象  视觉上没有效果//2,负责控制视图的显示方式//3,负责通知视图的显示内容//4,ios平台赋予的,收到内存警告和检测设备旋转@interface CHViewContr ...

  4. iOS视图控制器之间delegate传值教程

    之前在StackOverFlow上看到一篇讲传值(segue传值和delegate传值)的文章,感觉讲的非常清晰,就将delegate部分翻译了一下.有兴趣能够看看. 原文: http://stack ...

  5. [Xcode 实际操作]三、视图控制器-(4)使用UINavigationController导航栏和工具栏

    目录:[Swift]Xcode实际操作 本文将演示如何显示和隐藏导航视图的导航栏和工具栏 打开第一个视图控制器 import UIKit class FirstSubViewController: U ...

  6. 从C#到Objective-C,循序渐进学习苹果开发(6)--视图控制器的使用

    本随笔系列主要介绍从一个Windows平台从事C#开发到Mac平台苹果开发的一系列感想和体验历程,本系列文章是在起步阶段逐步积累的,希望带给大家更好,更真实的转换历程体验.本篇主要开始介绍基于XCod ...

  7. [Xcode 实际操作]三、视图控制器-(3)使用UINavigationController视图控制器

    目录:[Swift]Xcode实际操作 本文将演示导航视图控制器的使用. 选择项目导航区的资源文件夹.需要导入两张图片,作为选项卡控制器的图标. [+]->[Import]->选择图片-& ...

  8. [Xcode 实际操作]三、视图控制器-(5)使用UINavigationController视图入栈和出栈

    目录:[Swift]Xcode实际操作 本文将演示使用导航控制器的几个跳转方式 选择编辑第二个视图控制器文件 import UIKit //定义一个全局变量,用来记录当前显示区域的视图的编号 clas ...

  9. storyboard三种sugue 和 跳转场景的三种方式 以及控制器之间的传值

    Storyboard引入了2个概念:1. scene:一个场景,由一个viewController和相关的xib表示. 2. segue:在这是用于连接scenes,其有多种类型,iphone包括:P ...

随机推荐

  1. 一丶webservice执行存储过程

    返回值组合: json返回 StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("\&qu ...

  2. Java ArrayList中去掉相同的元素并保留相同元素中的最后一个

    实现思路:将list对象循环两次,拿外层数据和里面的数据对比,一样的删除外层(外层元素肯定比内存的靠前),如果一样的话,删除外层数据,这样最后输出外层数据的list,结果就能保证唯一性,并且保留了后面 ...

  3. HTML页面中解决内容元素随窗口变化布局变乱问题

    1.给body加上一个min-width最小宽度,以px为单位,这样当页面变小时,当达到你所设置的最小宽度,body的宽度不再改变,超出的部分会用横向滚动条显示,其内所有元素的布局也不会受影响. 2. ...

  4. 读懂CommonJS的模块加载

    叨叨一会CommonJS Common这个英文单词的意思,相信大家都认识,我记得有一个词组common knowledge是常识的意思,那么CommonJS是不是也是类似于常识性的,大家都理解的意思呢 ...

  5. POJ-1328-放置雷达

    这是一道贪心的题目,首先我们要知道,我们放置雷达的话我们可以做一个转换,就是已知岛屿的点坐标的时候,我们可以算一下,这个点以d为半径与x轴交点之间的线段在x轴上的投影,然后我们只需要在这个投影范围内设 ...

  6. InnoDB INFORMATION_SCHEMA Buffer Pool Tables

    InnoDB INFORMATION_SCHEMA Buffer Pool Tables InnoDB INFORMATION_SCHEMA缓冲池表提供有关InnoDB缓冲池中页面的缓冲池状态信息和元 ...

  7. Linux test命令

    test命令 长格式的例子: test "$A" == "$B" && echo "Strings are equal" t ...

  8. ps---打开文件及图片保存格式

    1.打开图片,可以按Ctrl或者Shift来进行多张图片的选择或者用鼠标框选. 2.勾选图像序列,可以选择命名上有次序的多个图像. 3. PSD是ps里面的标准保存格式,包含颜色.图层.通道.路径.动 ...

  9. 让自己习惯C++

    条款1.C++是一个语言联邦 过程形式(procedural) 面向对象形式(object-oriented) 函数形式(function) 泛型形式(generic) 元编程形式(metaprogr ...

  10. LeetCode02-两数相加

    ''' 给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表示 ...