首先, 先创建三个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. Perl: hash散列转换为Json报错集, perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $

    bash-2.03$ ./u_json.pl Can't locate object method "encode" via package "JSON" at ...

  2. [bzoj4899]记忆的轮廓 题解(毒瘤概率dp)

    题目背景 四次死亡轮回后,昴终于到达了贤者之塔,当代贤者夏乌拉一见到昴就上前抱住了昴“师傅!你终于回来了!你有着和师傅一样的魔女的余香,肯定是师傅”.众所周知,大贤者是嫉妒魔女沙提拉的老公,400年前 ...

  3. margin塌陷和margin合并问题及解决方案

    margin塌陷 先举个例子 <style> body{ background-color:#000; } .wrapper{ width:200px; height:200px; bac ...

  4. 「 Luogu P2801 」 教主的魔法——分块

    # 解题思路 修改,就是一个区间修改的常规操作,但是为了迎合查询的需要,对两端的不完整的块需要暴力重构,重新进行排序操作,保证每一块都是单调上升的顺序. 然后再说进行查询的操作,起初,我们需要在每一个 ...

  5. xmind 8 安装后启动失败(未提示错误信息)

      xmind 8 安装后启动失败   前言 家里的计算机也安装了xmind,启动之后界面显示xmind的启动图标,几秒之后启动图标消失(闪退了),然后留我一脸懵逼.想着卸载了安装一个新的应该没有问题 ...

  6. python基础(二) —— 流程控制语句

    编程语言中的流程控制语句分为以下几类: 顺序语句 分支语句 循环语句 其中顺序语句不需要单独的关键字来控制,就是按照先后顺序一行一行的执行,不需要特殊的说明. 下面主要是 分支语句 和 循环语句的说明 ...

  7. spring tool suite (sts) 创建springmvc(没有实践)

    摘自:STS(Spring Tool Suite)建立默认的spring mvc项目 老外的原创,网址:http://www.codejava.NET/frameworks/spring/spring ...

  8. 如何用纯 CSS 创作一种按钮被瞄准的交互特效

    效果预览 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. 在线演示 https://codepen.io/zhang-ou/pen/ELWMLr 可交互视频教程 此视 ...

  9. Django框架基础知识03-模板变量及模板过滤器

    模板变量及模板过滤器. 1.模板路径的查找 -查找顺序 1.尝试,在app目录下存放模板. -两种方案 1.app项目文件夹下存放. 2.templates文件夹下分类存放. 首先查找项目settin ...

  10. Python的串口

    要使用python中的串口,可以下载pywin32-224-cp36-cp36m-win_amd64.whl去安装或者pip install去安装. 调试下来,有一点很不爽,读取read()数据的ti ...