NSNotification(通知)
2016-04-13 10:16
519 查看
//创建一个消息对象 NSNotification * notice = [NSNotification notificationWithName:@"notification" object:nil userInfo:@{@"key":@"value"}]; //发送消息 [[NSNotificationCenter defaultCenter]postNotification:notice];
//获取通知中心单例对象 NSNotificationCenter * center = [NSNotificationCenter defaultCenter]; //添加当前类对象为一个观察者,name和object设置为nil,表示接收一切通知 [center addObserver:self selector:@selector(notice:) name:@"notification" object:nil];
-(void)notice:(NSNotification *)sender{ NSLog(@"%@",sender.userInfo[@"key"]); }
//释放通知
-(void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
相关文章推荐
- iOS 数据库 sql
- hibernate一对多注解懒加载失效问题
- SQL Server数据转到Oracle 数据库(一)
- Android studio 编译失败Error:Could not read entry ':app:processDebugManifest' from cache taskArtifacts.b
- vim配置文件和插件
- Cocos2dx Failed to write injected code block to PDB
- [倍增 堆] BZOJ 4458 GTY的OJ
- CloseableHttpClient加载证书来访问https网站
- Windows 10 操作系统启用旧版本的 Windows照片查看器
- delphi 712 Word 2
- mac 锁屏
- android:inputType常用取值
- PHP与C的区别
- 上图片预览前端脚本
- 博客引用书单
- 第6章HTTP
- arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf、gnueabi区别
- 对于Swift的Enum,文档上没有说的
- vb中typename函数
- Android Studio @Bind的用法,自动生成findViewById无需再实例化控件