一个简单的NSNotificationCenter使用
来源:互联网 发布:linux 桌面开发 编辑:程序博客网 时间:2024/05/19 06:47
一个简单的NSNotificationCenter的使用,在我看来分为四步.
1.注册一个通知
[[NSNotificationCenterdefaultCenter addObserver:self selector:@selector(scrllowTop:) name:kScrollToTopKey object:nil];//scrllowTop:响应的事件//kScrollToTopKey:通知的名称
2.发送通知
[[NSNotificationCenter defaultCenter]postNotification Name:kScrollToTopKey object:nil];//在需要使用的地方,加入这段代码,到时候,使用了这段代码以后就激活了这个通知,从而调用起响应事件
3.回到注册通知的地方,响应通知里的事件
- (void)scrllowTop:(NSNotification *)notification{//响应事件,具体的方法内容}
4.退出的时候,dealloc
- (void)dealloc{[[NSNotificationCenter defaultCenter]removeObserver:self name:kScrollToTopKey object:nil];//释放内存}
有了这四个步骤,一个简单的通知就基本完成了
0 0
- 一个简单的NSNotificationCenter使用
- NSNotificationCenter 用法 一个简单的使用 NSNotificationCenter 的代码例子
- NSNotificationCenter 的简单使用
- NSNotificationCenter的简单使用总结
- ios NSNotificationCenter 的简单使用
- iOS NSNotificationCenter的简单使用
- iOS中NSNotificationCenter的简单使用
- NSNotificationCenter简单使用
- NSNotificationCenter的简单应用
- NSNotificationCenter的简单应用
- NSNotificationCenter的一个问题
- iOS监听模式系列之NSNotificationCenter的简单使用
- NSNotificationCenter 的使用
- NSNotificationCenter 的使用
- NSNotificationCenter 的使用
- NSNotificationCenter 的使用
- NSNotificationCenter 的使用
- NSNotificationCenter 的使用详解
- Linux发布25周年 正日益庞大和专业
- 谈VC++对象模型
- Gray空间填充曲线
- 四、VR全景图显示器开发 ---- Android VR视频/Google VR for Android /VR Pano/VR Video
- Query对象
- 一个简单的NSNotificationCenter使用
- 【神经网络与深度学习】在Windows8.1上用VS2013编译Caffe并训练和分类自己的图片
- 五、VR视频播放器开发 ---- Android VR视频/Google VR for Android /VR Pano/VR Video
- 杂花生树(六)
- Java 学习笔记(0x0D) final关键字
- 老李linux配置tomcat
- DP方程+离散化——Codeforces Round #371 (Div. 1) C
- 事务处理
- 初学者1