Segue传递数据
来源:互联网 发布:mac看不到隐藏文件 编辑:程序博客网 时间:2024/06/16 21:07
我们在使用Segue进行跳转的时候,往往需要传递一些数据,我们在下面的方法中进行数据传递的准备工作:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
此方法包含两个参数:
- segue:跳转的Segue,其中包含跳转的源Controller和目标Controller,我们可以获取到这两个controller的对象,并进行进一步操作。
- sender:触发这个Segue的对象。
下面进行实例演示:
1. 创建一个Single View Application,在storyboard中添加一个View Controller,然后创建一个类,命名为SecondViewController,将这个类与新添加的View Controller关联起来。
2. 在第一个ViewController页面上添加一个button,并为此button添加一个segue,指向第二个ViewController。将这个Segue的identifier设置为”passdatasegue”。
3. 在SecondViewController的页面上添加一个label,并为其创建一个IBOutlet,名字为secondLabel,前三步效果如下图所示:
4. 在ViewController.m中添加如下代码:
#import "SecondViewController.h"...- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([segue.identifier isEqualToString:@"passdatasegue"]) { NSString *dataPassed = @"This is the data"; SecondViewController *secVC = [segue destinationViewController]; //将Key为dataFromVC的值设为dataPassed,这里的"dataFromVC",代表SecondViewContrller中的同名属性,因此需要在SecondViewController中创建这个属性 [secVC setValue:dataPassed forKey:@"dataFromVC"]; }}
- 在SecondViewController中添加如下代码:
@interface SecondViewController ()...@property (strong, nonatomic) NSString *dataFromVC;@end...- (void)viewDidLoad { [super viewDidLoad]; _secondLabel.text = [self valueForKey:@"dataFromVC"];}...
运行程序,效果如下所示:
阅读全文
0 0
- storyboard segue 传递数据
- Segue传递数据
- Segue --数据传递、顺传、逆传
- 使用segue页面间传递数据
- 使用StoryBoard:用Segue传递数据
- StoryBoard 使用segue页面间传递数据
- StoryBoard学习(5):使用segue页面间传递数据
- StoryBoard学习(5):使用segue页面间传递数据
- Segue回传数据
- OC笔记 - 控制器管理、UINavigationController、segue、控制器的数据传递(2015.3.16)
- iOS中使用storyboard实现页面跳转,Segue详解及简单的数据传递
- iOS开发点滴 - 如何通过Segue写代码传递数据从一个ViewController到另一个ViewController(Swift代码)
- SEGUE
- Segue
- iOS 演示 Modal Segue 的使用,包括参数如何从呈现者传递到 ModalView 以及数据如何从 ModalView 传回呈现者(利用委托对象)
- IOS storyboard 无Segue连接,手动跳转,并传递变量
- Swift - 纯代码实现页面segue跳转,以及参数传递
- Swift - 纯代码实现页面segue跳转,以及参数传递
- CAD 关于打断和合并对象
- Android系统编译常见问题
- 常用ajax_验证_提交_回调
- BOM
- vtigerCRM620 安装教程
- Segue传递数据
- codevs1403 新三国争霸 (最小生成树+dp)
- poi读取excel,支持合并单元格
- js中的touch事件及gesture(手势)事件
- 物体碰撞,勾股定理,唯一还记得的数学知识
- 让webapi统一返回JSON数据格式
- AdMob接入踩坑记
- Gdevops全球敏捷运维峰会-广州站即将于11月召开!
- easyui校验器扩展