一、总结几种关于ViewControllers之间传值的方式(从父视图向子视图传值)
2014-02-23 23:13
471 查看
接触ios时间比较短,遇到很多问题,ViewController之间的传值方式是其中一个比较疑惑的问题之一
经查阅apple developer library,总结出以下几种传值方式(若有错误或者不对之处,请不必留情直接指出):
以FirstViewController、SecondViewContrller两个视图举例:
一、将FirstViewController的值 传到 SecondViewController (从父视图向子视图传值)
1、在secondViewController中创建@property
2、在secondViewController中创建变量和操作方法
经查阅apple developer library,总结出以下几种传值方式(若有错误或者不对之处,请不必留情直接指出):
以FirstViewController、SecondViewContrller两个视图举例:
一、将FirstViewController的值 传到 SecondViewController (从父视图向子视图传值)
1、在secondViewController中创建@property
//SecondViewController.h 中创建@property @property (nonatomic) NSString *data; //在FirstViewController.m中导入 #import "SecondViewController.h" //在需要创建SecondViewViewController视图并需传值时 SecondViewController *secondViewContrller = [[SecondViewController alloc] initWithNibName: @"SecondViewControlle" bundle:nil]; secondViewController.data = @"Passing Data Forward"; [self.view addSubview:secondViewController.view]
2、在secondViewController中创建变量和操作方法
//在SecondViewController.h中加入 @interface SecondViewController : UIViewController{ NSString *data; } - (void)setData: (NSString *)set; //在SecondViewController.m中加入 - (void)setData: (NSString *)set{ data = set; } //在FirstViewController.m中 #import "SecondViewController.h" //创建SecondViewController视图 SecondViewController *secondViewContrller = [[SecondViewController alloc] initWithNibName: @"SecondViewControlle" bundle:nil]; [secondViewController setData:@"Passing Value"]; [self.view addSubview:secondViewController.view];
相关文章推荐
- KMP和扩展KMP
- 回顾曾经找工作和工作的一些事
- 11-hibernate实战 多对一对象模型和关系模型映射
- Android知识点回顾
- Java Servlet 中文API说明
- 使用DataTable更新数据库
- Hadoop核心架构HDFS+MapReduce+Hbase+Hive内部机理详解
- 安装时提示找不到Office.zh-cn目录下的X文件
- Ajax请求的四种方式
- 配置ADFS Outlook Client.
- annotations 和 fluent api的选择
- URAL 1876 Centipede's Morning(数学)
- jsp基础语法二:
- Android菜鸟的成长笔记(17)—— 再看Android中的Unbounded Service
- Android菜鸟的成长笔记(17)—— 再看Android中的Unbounded Service
- 在VC中调用WebService
- 为什么重写equals方法,一定要重写HashCode方法?
- Android中Input型输入设备驱动原理分析
- webservice系列教学(14)-如何调用webservice(vc5)-.NET教程,Web Service开发
- 《专业嵌入式软件开发》