传值
2016-04-07 10:19
302 查看
通知中心传值
代理传值
头文件 // Common.h // 通知中心传值 // #ifndef Common_h #define Common_h #define NotificationName @"changeValur" #endif /* Common_h */ ------------------------------------------------------------------------------ // ViewController.m // 通知中心传值 // #import "ViewController.h" #import "Common.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UITextField *text1; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 通知的接受者(接收到通知后响应事件的对象) 接受到通知后响应的事件 当前通知的名称 当前通知的发送者(一般为nil) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeValueText:) name:NotificationName object:nil]; // Do any additional setup after loading the view, typically from a nib. } -(void)changeValueText:(NSNotification *)nsnotification{ //获取通知发送者的发送的信息 NSDictionary *dict = nsnotification.userInfo; //键值 _text1.text = dict[@"value"]; } -(void)dealloc{ //移除通知 [[NSNotificationCenter defaultCenter]removeObserver:self name:NotificationName object:nil]; } -------------------------------------------------------------------------------- // ChangeViewController.m // 通知中心传值 // #import "ChangeViewController.h" #import "Common.h" @interface ChangeViewController () @property (weak, nonatomic) IBOutlet UITextField *text2; @end @implementation ChangeViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (IBAction)back:(UIButton *)sender { //发送通知的名称 发送者(一般为nil) 发送内容 [[NSNotificationCenter defaultCenter] postNotificationName: object:nil userInfo:@{@"value":_text2.text}]; [self dismissViewControllerAnimated:YES completion:nil]; }
代理传值
相关文章推荐
- js 对象属性复制到另一个对象
- 重构13天 抽取方法对象(Extract Method Object)
- PHP使用Mysqli类库实现完美分页效果的方法
- 搜索算法-二分搜索-方程解问题(problem 1001)
- UVA 1006 水题
- powerpc PCIe驱动学习
- 专访知名民间黑客洪流:未竟武侠梦,仗剑行天涯
- Python字符串
- 我的python学习之路
- httpClient上传下载文件
- 读书笔记《高级UNIX环境编程》
- python学习笔记(异常处理)
- jQuery EasyUI使用教程之根据条件更换数据网格行背景颜色
- Java 设计模式讲解
- 并发和并行的区别
- 修改浏览器DNS缓存时间、清除系统DNS缓存
- SDUT 3330----顺序表应用6:有序顺序表查询(二分查找)
- Likely root cause: java.lang.IllegalStateException: jar hell!
- Qt Quick 简介
- 3.8.3 MAIL_STREAM流