通知中心
来源:互联网 发布:淘宝直播里的衣服质量 编辑:程序博客网 时间:2024/04/27 17:04
通知中心 (先注册观察者,后发送通知)
- (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];}
接收通知中心发送的通知
- (void)didReceiveNotification:(NSNotification *)sender{ self.firstLabel.text = sender.userInfo[@"text"]; NSLog(@"welcome back!");}
移除通知中心的观察者(首选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
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 通知中心
- 《通知中心》
- 通知中心
- 通知中心
- 通知中心NSNotificationCenter
- IOS Notification 通知中心
- 迷宫
- c语言sizeof求结构体的大小
- 编译java程序时的一个问题
- hdu1004Let the Balloon Rise(map容器经典例题)
- UICollectionView基础
- 通知中心
- iOS开发 中的 多线程
- 如何高效的通过BP算法来训练CNN
- excel的XML映射
- uestc893
- CSS中的position
- FragmentTabHost切换Fragment时避免UI重新加载
- lintcode(103) Linked List Cycle II
- Word文档中怎么插一条水平线