通知传值
来源:互联网 发布:递延所得税资产 知乎 编辑:程序博客网 时间:2024/06/03 20:32
-> 大多反向传值(必须先注册观察者,再发送通知,才能收到通知的原因)
//// ViewController.m// -//#import "ViewController.h"#import "SecondVC.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; [_nextButton addTarget:self action:@selector(nextPage) forControlEvents:UIControlEventTouchUpInside]; // 1.注册观察者 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(observerDidReceived:) name:@"PassToPreviousNotification" object:nil];}// 2.观察到,执行方法- (void)observerDidReceived:(NSNotification*)notification{ _receiveLabel.text = [notification.userInfo objectForKey:@"valueString"];}-(void)nextPage{ SecondVC * secondVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"SecondVC"]; [self presentViewController:secondVC animated:true completion:nil];}// 3.释放通知- (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self];}@end
//// SecondVC.m////#import "SecondVC.h"@interface SecondVC ()@end@implementation SecondVC- (void)viewDidLoad { [super viewDidLoad]; [_backButton addTarget:self action:@selector(backToPreviousPage) forControlEvents:UIControlEventTouchUpInside];}- (void)backToPreviousPage{ // 发送通知 [[NSNotificationCenter defaultCenter] postNotificationName:@"PassToPreviousNotification" object:self userInfo:@{@"valueString":_contentTextF.text}]; [self dismissViewControllerAnimated:true completion:nil];}@end
阅读全文
0 0
- [Object-c] 通知二 通知传值
- 通知传值
- NSNotification 通知传值
- 通知传值(NSNotificationCenter)
- 通知传值
- 通知传值(NSNotificationCenter)
- 通知传值
- NSNotification 通知传值
- NSNotificationCenter 通知传值
- iOS通知传值
- iOS通知传值
- IOS 通知传值
- iOS 通知传值
- iOS通知传值
- 通知传值
- 通知跳转传值
- iOS通知传值
- iOS 通知传值
- java操作远程共享目录
- 修改mysql数据库的账号的过期时间
- 卡片IOT 电源选择
- android-studio 鼠标悬浮提示
- Textview设置超链接点击事件
- 通知传值
- android反编译工具
- sdk 和 api 的区别
- Git使用手册:git commit -m/-am/-a -m 提交文件至本地仓库区
- docker安装
- IO流
- AWS EC2主机类型的区别和联系
- myeclipse包变成文件夹
- 23种模式-单列模式