UI 07 _ 导航视图控制器 与 属性传值
首先, 先创建三个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 _ 导航视图控制器 与 属性传值的更多相关文章
- Snail—UI学习之导航视图控制器UINavigationController(系统)
背景 有一个根视图控制器 然后跳转到第一个界面 第一个界面能够返回到根视图 也能够跳转到第二个视图 第二个视图能够直接返回到根视图 新建三个ViewController RootViewCon ...
- ios 导航视图控制器 跳转
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- 步步入佳境---UI入门(3) --单视图控制器
视图控制器特点//1,抽象 视觉上没有效果//2,负责控制视图的显示方式//3,负责通知视图的显示内容//4,ios平台赋予的,收到内存警告和检测设备旋转@interface CHViewContr ...
- iOS视图控制器之间delegate传值教程
之前在StackOverFlow上看到一篇讲传值(segue传值和delegate传值)的文章,感觉讲的非常清晰,就将delegate部分翻译了一下.有兴趣能够看看. 原文: http://stack ...
- [Xcode 实际操作]三、视图控制器-(4)使用UINavigationController导航栏和工具栏
目录:[Swift]Xcode实际操作 本文将演示如何显示和隐藏导航视图的导航栏和工具栏 打开第一个视图控制器 import UIKit class FirstSubViewController: U ...
- 从C#到Objective-C,循序渐进学习苹果开发(6)--视图控制器的使用
本随笔系列主要介绍从一个Windows平台从事C#开发到Mac平台苹果开发的一系列感想和体验历程,本系列文章是在起步阶段逐步积累的,希望带给大家更好,更真实的转换历程体验.本篇主要开始介绍基于XCod ...
- [Xcode 实际操作]三、视图控制器-(3)使用UINavigationController视图控制器
目录:[Swift]Xcode实际操作 本文将演示导航视图控制器的使用. 选择项目导航区的资源文件夹.需要导入两张图片,作为选项卡控制器的图标. [+]->[Import]->选择图片-& ...
- [Xcode 实际操作]三、视图控制器-(5)使用UINavigationController视图入栈和出栈
目录:[Swift]Xcode实际操作 本文将演示使用导航控制器的几个跳转方式 选择编辑第二个视图控制器文件 import UIKit //定义一个全局变量,用来记录当前显示区域的视图的编号 clas ...
- storyboard三种sugue 和 跳转场景的三种方式 以及控制器之间的传值
Storyboard引入了2个概念:1. scene:一个场景,由一个viewController和相关的xib表示. 2. segue:在这是用于连接scenes,其有多种类型,iphone包括:P ...
随机推荐
- ::Sleep(0)的使用
::Sleep(0)的使用 This function causes a thread to relinquish the remainder of its time slice and become ...
- 使用Spring AOP切面解决数据库读写分离
http://blog.jobbole.com/103496/ 为了减轻数据库的压力,一般会使用数据库主从(master/slave)的方式,但是这种方式会给应用程序带来一定的麻烦,比如说,应用程序如 ...
- JavaEE-03 JSP数据交互02
学习要点 application pageContext JSP对象作用域 cookie application 作用 类似于系统的“全局变量”,用于在同一个服务器内的所有用于之间的数据共享,对于整个 ...
- IDEA无法编译源码,IDEA查看源码出现/* compiled code */
打开Settings -> Plugins 搜索dec,选中,确定,重启,解决
- Brackets POJ - 2955
解法 区间dp例题,每次枚举分段点的时候先更新如果开始到结束区间端点有闭合的括号,那么dp[start][end]=dp[start+1][end-1]+2其他照常枚举即可 代码 #include & ...
- Jenkins出现 {"changed": false, "msg": "mkdir: cannot create directory ‘/root/.ansible/tmp/ansible-tmp-1552390265.8-253945919613076’: No space left on device\n", "unreachable": true}
之前部署Jenkins没有遇到过这个问题,百度也找不到相关内容,无奈用过google翻译了一下,显示内存不足,上到服务器查询df -h 发现use% 100% 由于日志等文件导致服务器磁盘空间满了,引 ...
- MongoDB中导入数据命令的使用(mongoimport)
MongoDB中导入数据命令的使用(mongoimport) 制作人:全心全意 语法: mongoimport <options> <file> 介绍: 该命令可以将CSV,T ...
- 蓝牙bluez学习(1) Stack Architecture
Bluez支持的features Core Specification 4.2 (GAP, L2CAP, RFCOMM, SDP, GATT) Classic Bluetooth (BR/EDR) B ...
- float 和 clear
float 特性1:可以为行内浮动元素设置宽高 <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...
- InsecureRequestWarning: Unverified HTTPS request is being made.解决方法
在前面添加: import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning reque ...