VIM教程与学习资料汇总
2011-10-31 16:53
651 查看
在IOS开发中,通告的作用不言而喻,它在一个项目中就像是一个特权,不受类等的约束,方便至极,对于每一个通告,区分他们的标示是他们的名字name。
发送通告,发送通告时可以带一个参数,此参数需为NSDictionary字典类型:
注册通告观察器:
[/code]
接收到通告后调用方法:
10.26更新
通告中心不会保留观察器,在通告中心注册过的对象必须在释放前取消注册。否则,相应的通告再次出现时,通告中心仍然会像该观察器发送消息,因为相应的对象已经释放,所以会导致程序崩溃。
取消注册:
}
[/code]
发送通告,发送通告时可以带一个参数,此参数需为NSDictionary字典类型:
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init]; [dic setObject:@"I'm a notification!" forKey:@"content"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object:self userInfo:(NSDictionary *)dic];
注册通告观察器:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getContent:) name:@"[code]myNotification" object:nil];
[/code]
接收到通告后调用方法:
- (void)getContent:(NSNotification *)note { NSDictionary *dic = [note userInfo]; NSLog("The Content of myNotification : %@", [dic objectForKey:@"content"]); }
10.26更新
通告中心不会保留观察器,在通告中心注册过的对象必须在释放前取消注册。否则,相应的通告再次出现时,通告中心仍然会像该观察器发送消息,因为相应的对象已经释放,所以会导致程序崩溃。
取消注册:
- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [code] [super dealloc];
}
[/code]
相关文章推荐
- VIM教程与学习资料汇总
- VIM教程与学习资料汇总
- VIM教程与学习资料汇总
- VIM教程与学习资料汇总(转载自善用佳软)
- PPT、EXCEL、SPSS、水晶易表教程与学习资料汇总
- 黄聪:Python语言编程学习资料(电子书+视频教程)下载汇总
- vim学习资料汇总
- 《循序渐进》前端学习视频教程资料汇总
- Windows及linux环境下PHP的搭建教程学习资料汇总
- 转:Python语言编程学习资料(电子书+视频教程)下载汇总:
- 转:Python语言编程学习资料(电子书+视频教程)下载汇总
- Python语言编程学习资料(电子书+视频教程)下载汇总
- 20、新手入手树莓派教程--学习路线和资料汇总
- Python语言编程学习资料(电子书+视频教程)下载汇总
- Vim学习资料汇总
- 1、激光雷达学习笔记--资料汇总
- 各类学习资料(网址)汇总~
- 【C++资料免豆下载】大量教程+工具+源码下载地址汇总
- iOS超全开源框架、项目和学习资料汇总--数据库、缓存处理、图像浏览、摄像照相视频音频篇
- ROS(indigo)机器人操作系统学习资料和常用功能包汇总整理(ubuntu14.04LTS)