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 ...
随机推荐
- QT +坐标系统 + 自定义控件 + 对象树的验证(自动进行析构)_内存回收机制
通过创建一个新的按钮类,来进行析构函数的验证,即对象树概念的验证.当程序结束的时候会自动的调用析构函数, 验证思路: 要验证按钮会不会自动的析构,(即在QPushButton类里面的析构函数添加qDe ...
- C++构造函数(复制构造函数)、析构函数
注:若类中没有显示的写如下函数,编译会自动生成:默认复制构造函数.默认赋值构造函数(浅拷贝).默认=运算符重载函数(浅拷贝).析构函数: 1.默认构造函数(默认值)构造函数的作用:初始化对象的数据成员 ...
- 【传智播客】Libevent学习笔记(二):创建event_base
目录 00. 目录 01. 简介 02. 创建默认的event_base 03. 创建复杂的event_base 3.1 event_config_new函数 3.2 event_base_new_w ...
- 【分享】 封装js操作textarea 方法集合(兼容很好)。
请使用下面的btn操作. 虽然你现在看来没什么用,当要用的时候又到处找资料,还不如现在收集一下. 在DOM里面操作textarea里面的字符,是比较麻烦的. 于是我有这个封装分享给大家 ...
- ios之UITableView
今天要分享的是IOS开发中一个使用率非常高的一个控件-------UITableView,这两天正在使用tableview做信息的显示,在写代码时对tableview和tableviewcell的几种 ...
- 南邮CTF--bypass again
南邮CTF--bypass again 提示:依旧弱类型,来源hctf 解析: 源代码: if (isset($_GET['a']) and isset($_GET['b'])) { if ($_G ...
- 基于flask的网页聊天室(二)
基于flask的网页聊天室(二) 前言 接上一次的内容继续完善,今天完成的内容不是很多,只是简单的用户注册登录,内容具体如下 具体内容 这次要加入与数据哭交互的操作,所以首先要建立相关表结构,这里使用 ...
- Android开发——使用ADB Shell命令实现模拟点击(支付宝自动转账实现)
首先声明,本人反对一切利用技术的违法行为 本文的实现代码已经销毁,本文以介绍流程为主 1.这里所说的模拟点击不是在自己的APP里点击,点自己APP上的控件没什么好说的 不仅是支付宝转账,其他的获取别人 ...
- linux赋权限
给该文件夹赋权限命令 chmod u+x service-hcm-job.sh
- [luoguP1627] 中位数(模拟?)
传送门 水题,怎么评到这个难度的? #include <cstdio> #include <iostream> #define N 200001 int n, b, p, an ...