iOS通知中心NSNotificationCenter
2015-12-01 15:47
405 查看
注:一个应用程序中只有一个通知中心
/// @brief 创建一个通知中心对象
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
/// @brief 向通知中心注册观察者,第一个参数为观察的对象所在类,第二个参数为观察到以后所调用的方法,第三个参数为观察的事件,第四个参数为要传的参数
[nc addObserver:self selector:@selector(keyboardShowUp) name:UIKeyboardWillShowNotification object:nil];
/// @brief 发送通知,第三个参数为发送的消息
[[NSNotificationCenter defaultCenter] postNotifiationName:@"发送的通知名" object:self userInfo:dict];
/// @brief 获取通知消息,noti为通知中心的对象名
NSDictionary *dict = noti.userInfo
/// @brief 从通知中心移除观察者
[[NSNotificationCenter defaultCenter] removeObserver:self];
/// @brief 创建一个通知中心对象
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
/// @brief 向通知中心注册观察者,第一个参数为观察的对象所在类,第二个参数为观察到以后所调用的方法,第三个参数为观察的事件,第四个参数为要传的参数
[nc addObserver:self selector:@selector(keyboardShowUp) name:UIKeyboardWillShowNotification object:nil];
/// @brief 发送通知,第三个参数为发送的消息
[[NSNotificationCenter defaultCenter] postNotifiationName:@"发送的通知名" object:self userInfo:dict];
/// @brief 获取通知消息,noti为通知中心的对象名
NSDictionary *dict = noti.userInfo
/// @brief 从通知中心移除观察者
[[NSNotificationCenter defaultCenter] removeObserver:self];
相关文章推荐
- iOS 控制器View的生命周期及相关函数
- IOS多线程编程
- iOS 用NSAttributedString处理文字大小不一致情况
- iOS中生成本地二维码
- iOS 引入支付宝 缺少 #include <openssl/asn1.h>
- ios项目整理(一)第三方框架
- iOS 简单的一些动画效果
- iOS 创建单例的三种方法
- iOS设置颜色渐变
- iOS系统自带指纹验证的使用
- iOS layer层与优化(界面卡顿)
- 《使用 VIPER 构建 iOS 应用》读后感
- iOS调试错误 linker command failed with exit code 1 (use -v to see invocation)
- iOS block在两个页面间的简单传值
- IOS的xcode7的不需要开发者账号的调试步骤
- IOS的ScrollView使用方法(教你超出部分怎么玩)
- IOS代码库配上pod使用极其方便
- iOS一些重要的应用目录
- IOS动画ViewAnimations
- iOS开发--一些重要的总结