iOS 通知的基本使用传值
来源:互联网 发布:淘宝卖家怎么打折商品 编辑:程序博客网 时间:2024/05/29 12:39
//设置通知
//获取通知中心
NSNotificationCenter
*nc = [
NSNotificationCenter
defaultCenter];
//通知中心 发送广播
/*
第一个参数就是通知的名字 第二个参数 谁发送的通知
第三个参数 通知的内容
这个方法内部会创建一个通知对象
*/
//把通知的内容放入字典中
NSDictionary
*dict = @{@
"status"
: @
"123"
};
//自定义的通知
[nc postNotificationName:kNotificationChangeStatus object:
self
userInfo:dict];
/***********************************************************************************/
//接收通知
//在viewDidLoad方法中注册观察者
//提前创建观察者
NSNotificationCenter
*nc = [
NSNotificationCenter
defaultCenter];
//注册观察者
//接收任意对象发送的kNotificationChangeStatus通知
[nc addObserver:
self
selector:
@selector
(changeLabelText:) name:kNotificationChangeStatus object:
nil
];
//实现接收通知方法
- (
void
)changeLabelText:(
NSNotification
*)nf{
//获取通知的内容
NSDictionary
*dict = nf.userInfo;
NSString
* isOn = dict[@
"status"
];
NSLog
(@
"%@"
, isOn);
}
//最后别忘了
//删除观察者
- (
void
)dealloc{
//删除观察者
[[
NSNotificationCenter
defaultCenter] removeObserver:
self
name:kNotificationChangeStatus object:
nil
];
}
0 0
- iOS 通知的基本使用传值
- IOS本地通知(UILocalNotification)的基本使用
- iOS通知传值的使用
- iOS通知Notification传值的使用
- iOS中通知传值的使用
- iOS之通知传值的使用
- iOS通知NSNotification传值的使用
- iOS---通知传值的使用
- iOS 通知传值的使用
- iOS通知传值的使用
- iOS通知传值的使用
- iOS 本地通知基本使用
- iOS 通知的基本用法
- iOS 通知的基本用法
- iOS 代理,通知和KVO的基本使用
- IOS通知的使用
- ios 通知的使用
- iOS通知的使用
- Linux安装JDK
- 线性表
- [LeetCode] 13. Roman to Integer
- POJ 1200 Crazy Search
- hdu 2222 Keywords Search(AC自动机模板)
- iOS 通知的基本使用传值
- 用jquery实现图片轮播
- 磁盘阵列 RAID 技术原理详解
- 晶/陶振不起振及使用注意事项
- CentOS安装 netdata 实时监视 Linux 系统性能
- [Tarjan缩点 拓扑序DP] SRM 499 1000pts
- BZOJ4570 SCOI2016 妖怪 凸包+双钩函数求最值
- Cloudera 5.7集群部署(三)--CM前台配置部署CDH
- 十六进制转换成十进制 二进制