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];//先创建一个ViewControllerMainViewController *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];
  // 创建一个UIViewUIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];view.backgroundColor = [UIColor orangeColor];[self.view addSubview:view];[view release];// 为了防止坐标系被篡改,我们把bar从半透明改为全透明.这样坐标系的原点会自己主动向下推64self.navigationController.navigationBar.translucent = NO;

内容方面的设置

//另外一种标题的设置self.navigationItem.title = @"骨头 商店";// 指定一些视图,作为titleViewUISegmentedControl *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;//属性传值第三步:里面的值赋给labelself.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

转载于:https://www.cnblogs.com/brucemengbm/p/7202073.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/572207.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

el表达式具体解释

引用内容百度百科(http://baike.baidu.com/view/1488964.htm) 參考百度百科&#xff0c;然后自己又加入了一部分自己感觉实用的东西&#xff0c;整理一下希望对大家有所帮助&#xff01;E L&#xff08;Expression Language&#xff09; 目的&#xff1a;为了使JSP写起来更加简…

MyBatis接口代理

MyBatis接口代理&#xff1a; 采用 Mybatis 的代理开发方式实现 DAO 层的开发&#xff0c;这种方式是目前的主流方式。Mapper 接口开发方法只需要程序员编写Mapper 接口&#xff08;相当于Dao 接口&#xff09;&#xff0c;由Mybatis 框架根据接口定义创建接口的动态代理对象&a…

编译OSG的FreeType插件时注意的问题

使用自己编译的freetype.lib&#xff0c;在编译osgdb_freetype插件项目时&#xff0c;报错LINK错误&#xff0c;找不到png的一堆函数 最简单的方式是不要使用PNG编译freetype。记住不要犯贱。 转载于:https://www.cnblogs.com/coolbear/p/7205906.html

openresty总结

协程 1.例如当获取的数据没有前后依赖关系时&#xff0c;可以使用ngx.thread.spawn和ngx.thread.wait同时从数据库不同的库、表或者不同来源&#xff08;mysql&#xff0c;redis等&#xff09;获取数据。https://github.com/openresty/lua-nginx-module#ngxthreadspawnhttps://…

PageHelper分页插件使用

分页插件PageHelper&#xff1a; MyBatis没有分页功能&#xff0c;需要手动编写LIMIT语句&#xff0c;可以使用第三方的插件来对功能进行扩展&#xff0c;分页助手PageHelper是将分页的复杂操作进行封装&#xff0c;使用简单的方式即可获得分页的相关数据 PageInfo&#xff1a;…

jquery插件开发通用框架

2017-07-24 更新&#xff1a;增加单例模式。 jquery插件开发框架代码&#xff1a; /** 插件编写说明&#xff1a;* 1、插件命名&#xff1a;jquery.[插件名].js&#xff0c;如jquery.plugin.js* 2、对象方法添加到jQuery.fn上&#xff0c;全局方法添加到jQuery对象本身上* 3、插…

Mybatis多表模型

多表模型&#xff1a; 多表模型分类 一对一&#xff1a;在任意一方建立外键&#xff0c;关联对方的主键。一对多&#xff1a;在多的一方建立外键&#xff0c;关联一的一方的主键。多对多&#xff1a;借助中间表&#xff0c;中间表至少两个字段&#xff0c;分别关联两张表的主键…

关于zkfc与zkserver频繁断开的问题

详见http://blog.csdn.net/dslztx/article/details/51596951转载于:https://www.cnblogs.com/roger888/p/7211625.html

高动态范围红外图像压缩

BF&DRC 近期看了一篇高动态范围红外图像压缩的文章&#xff0c;《New technique for the visualization of high dynamic range infrared images》.这篇文章主要利用双边滤波器把宽动态红外图像切割为基本图像和细节图像&#xff0c;再分别对基本图像和细节图像进行处理。对…

Mybatis构建sql语法

构建sql&#xff1a; 之前通过注解开发时&#xff0c;相关 SQL 语句都是自己直接拼写的。一些关键字写起来比较麻烦、而且容易出错。MyBatis 给我们提供了 org.apache.ibatis.jdbc.SQL 功能类&#xff0c;专门用于构建 SQL 语句 常用方法&#xff1a; 查询功能的实现&#xf…

Mqtt协议IOS端移植3

ServerMqFramework.h #import "MqttFramework.h"interface ServerMqFramework : MqttFramework/*** brief 得到模块控制器的句柄单例** param [in] N/A* param [out] N/A* return void* note*/(ServerMqFramework*)getMQttServerFrameInstance;- (int)callBusine…

java第三课,流程控制语句

流程控制语句条件语句&#xff1a;if语句&#xff1a;*if&#xff08;条件 boolean类型&#xff09;{ true }*if(boolean表达式){true}else&#xff5b;false结果&#xff5d;*多重 if else if(){}else if(){}else *嵌套ifSwitch语句&#xff1a;*switch(表达式){ case…

在cli命令行上显示当前数据库,以及查询表的行头信息

在$HIVE_HOME/conf/hive-site.xml文件下加入以下配置文件 <property><name>hive.cli.print.header</name><value>true</value><description>Whether to print the names of the columns in query output.</description> </proper…

两点之间最短路径:弗洛伊德算法

弗洛伊德算法是计算无向有权图中两点间最短路径的算法&#xff0c;复杂度为O(n^3)。其思路是将两点间距离分为过&#xff08;指定的&#xff09;第三点或是不过&#xff0c;然后取它们的最小值&#xff0c;如此循环就可以得到两点之间真正的最小值。 void floyd() {for (int k …

最常用的JavaScript 事件

JavaScript 事件&#xff1a; 事件指的就是当某些组件执行了某些操作后&#xff0c;会触发某些代码的执行。 更多事件&#xff1a;https://www.w3school.com.cn/jsref/dom_obj_event.asp 常用的事件&#xff1a; 属性触发时机onabort图像加载被中断onblur元素失去焦点onchange…

Codevs 1025 选菜

1025 选菜 时间限制: 1 s空间限制: 128000 KB题目等级 : 黄金 Gold题解题目描述 Description在小松宿舍楼下的不远处&#xff0c;有PK大学最不错的一个食堂——The Farmer’s Canteen&#xff08;NM食堂&#xff09;。由于该食堂的菜都很不错&#xff0c;价格也公道&#xff0c…

SAS笔记(2) RETAIN语句

本文重点&#xff1a; 使用RETIAN,INPUT在每次循环执行时保留上一次PDV中的变量值。SUM语句和SET语句会自动RETAIN变量。1. RETAIN语句 1.1 Example 1 先来看看在DATA步不使用和使用RETAIN语句的差异 没有使用RETAIN: DATA WITHOUT_1;PUT "Before the INPUT statement: &…

Hive优化策略

hive优化目标 在有限的资源下&#xff0c;运行效率高。常见问题 数据倾斜、Map数设置、Reduce数设置等 hive运行 查看运行计划 explain [extended] hql 例子 explain select no,count(*) from testudf group by no; explain extended select no,count(*) from testudf group …

POJ 3268 Silver Cow Party (最短路径)

POJ 3268 Silver Cow Party &#xff08;最短路径&#xff09; Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidi…

GPU性能实时监测的实用工具

大家好,我是爱编程的喵喵。双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为CSDN博客专家、人工智能领域优质创作者。喜欢通过博客创作的方式对所学的…