通知的用法
来源:互联网 发布:古墓丽影崛起帧数优化 编辑:程序博客网 时间:2024/05/21 07:47
NSNotificationCenter是专门供程序中不同类间的消息通信而设置的。
1.注册通知
NSNotificationCenter* notification = [NSNotificationCenter defaultCenter];
[notification addObserver:self selector:@selector(change:) name:@"changeImage" object:nil];
//addObserver 这个是观察者,就是说在什么地方接收通知
//selector这个是收到通知后,调用何种方法;
//name:这个是通知的名字,也是通知的唯一标示,编译器就通过这个找到通知的。
2.处理消息
- (void) change:(NSNotification*)notification
{
id obj = [notification object];//获取到传递的对象
}
3.dealloc里注销通知
[[NSNotificationCenter defaultCenter] removeObserver:self];
4发送通知(在需要发送通知的类里)
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeImage" object:self];
//object:这个对象是自身,你要传谁的值
- 通知的用法
- 通知的用法
- 通知的用法
- 通知的用法,传值
- 创建通知-通知的用法
- iOS NSNotification 通知的用法
- 本地通知UILocalNotification的用法
- Android-- Toast通知的用法
- UILocalNotification 本地通知的用法
- iOS 通知的基本用法
- iOS 通知的基本用法
- Notification通知的基本用法
- Notification通知栏的用法
- Notification--------通知的基本用法
- Android中通知的基本用法
- 通知--Notification的功能与用法
- Android通知之Notification的多种用法
- 通知栏的相关用法记录
- 利用FileChannel复制文件
- Makefile中等号的使用
- 利用OGRE的海洋例子改成的水编辑器
- WebCore Rendering 4 - 绝对/固定定位和相对定位
- Select & SelectMany
- 通知的用法
- 一段登录代码
- 关键帧系统的实现(Hermite位置插值+Squad四元数空间的朝向插值)
- 为什么5%的技术人员开发效率是其他95%的20倍?
- 高效率3D图形程序中的骨骼
- Unix传奇
- Hdu3879 Base Station 最大权闭合子图 最大获利
- 如何避免网站出现优化过度
- 黑马程序员_JavaSE基础04 之 循环嵌套 函数重载 数组 内存空间划分