iOS_NSNotificationCenter(通知中心简单建立)
来源:互联网 发布:写真机软件 编辑:程序博客网 时间:2024/06/17 18:58
通知中心 (先注册观察者,后发送通知)
- (IBAction)buttonDidClicked:(UIButton *)sender { SecondViewController *secondVC = [[SecondViewController alloc] init]; [self.navigationController pushViewController:secondVC animated:YES]; // 通知中心 *注册* 观察者 // 监听 123 频道消息 // 主要作用不是传值,而是实现相隔较远的页面之间进行交互 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotification:) name:@"123" object:nil];}
接收通知中心发送的通知
#pragma mark - 接收通知中心发送的通知- (void)didReceiveNotification:(NSNotification *)sender{ self.firstLabel.text = sender.userInfo[@"text"]; NSLog(@"welcome back!");}
移除通知中心的观察者(首选pop)
#pragma mark - 移除通知中心的观察者(首选pop)// 如果内存控制好的话,也可以在dealloc里面写,ARC下也可以写dealloc- (void)dealloc{ // 移除所有的观察者 [[NSNotificationCenter defaultCenter] removeObserver:self]; // 移除指定的观察者 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"123" object:nil];}
发送通知
- (IBAction)backButtonDidClicked:(UIButton *)sender { // 发送通知 [[NSNotificationCenter defaultCenter] postNotificationName:@"123" object:nil userInfo:@{@"text":self.textField.text}]; [self.navigationController popViewControllerAnimated:YES];}
0 0
- iOS_NSNotificationCenter(通知中心简单建立)
- iOS_NSNotificationCenter(通知中心)
- iOS_NSNotificationCenter简单使用,
- 通知中心的简单使用
- NSNotificationCenter(通知中心)
- 通知中心(NSNotificationCenter)
- iOS通知中心的简单实现-YRSignal
- 简单实现iOS通知中心的功能
- IOS 通知中心(个人)
- NSNotification(通知中心)传值
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 解决Eclipse下maven项目的jar包无法发布到tomcat中的问题
- DAG最短路算法
- Android开发初学者问题
- return break
- MATLAB 练习01 数组与矩阵
- iOS_NSNotificationCenter(通知中心简单建立)
- 每一位攻城狮都不能错过的Visual Studio 2015正式版
- 猫猫学iOS 之微博项目实战(3)微博主框架-UIImage防止iOS7之后自动渲染_定义分类
- dictionary
- 月之数
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener问题解决
- linux cpu 信息查看
- 【leetcode】 26. Remove Duplicates from Sorted Array
- JavaScript第一日学习报告