OC中通知使用浅析
来源:互联网 发布:拷贝文件 linux 编辑:程序博客网 时间:2024/06/06 16:59
注册发送通知
//Refresh_Comment是通知的名字
[[NSNotificationCenterdefaultCenter] postNotificationName:Refresh_Comment object:nil userInfo:@{@"data":data}];
接收通知传过来的值(这个值放到"refreshComment"这个方法中)
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(refreshComment:)name:Refresh_Comment object:nil];
- (void)refreshComment:(NSNotification *)notification
{
_dataModel.commentCount = ((CircleData *)notification.userInfo[@"data"]).commentCount;
_comments = ((CircleData *)notification.userInfo[@"data"]).comments;
[_tableView reloadData];
}
dealloc移除通知
-(void)dealloc
{
[[NSNotificationCenterdefaultCenter] removeObserver:self];
}
注意:
向NSNotificationCenter中addObserver后,并没有对这个对象进行引用计数加1操作,它只是保存了地址。
在你不是销毁的时候,千万不要直接调用[[NSNotificationCenter defaultCenter] removeObserver:self]; 这个方法,因为你有可能移除了系统注册的通知。
在什么线程发通知,就会在什么线程执行通知的内容.
就是在页面出现的时候注册通知,页面消失时移除通知。一定要成双成对出现。
http://www.cocoachina.com/ios/20150120/10954.html
- OC中通知使用浅析
- oc中KVC,KVO,通知的使用
- 浅析iOS中Push通知的使用
- OC中Runtime浅析
- [oc学习笔记]通知中心传值的使用
- OC编程中通知的使用1(传值)
- OC编程中通知的使用2(监听)
- 浅析iOS中Push通知的使用【图文+视频】
- 浅析iOS中Push通知的使用【图文+视频】
- OC中代理和通知的概念
- OC-通知
- OC-通知
- OC-通知
- OC-代理、通知、block使用与使用差别
- OC中NSValue使用
- android中通知的使用
- swift中通知的使用
- Android中通知的使用
- hdoj4000Fruit Ninja【树状数组】
- c++ 特性: 右值引用与移动语义
- 引用指向的真正类名 getClass( ).getName( )
- Linux cmake 编译安装
- Sample Size Determination
- OC中通知使用浅析
- ios 9 网络适配
- 外部js书写规则
- Nginx增加PHP脚本的执行时间
- 鹅鹅鹅鹅鹅鹅饿鹅鹅鹅
- (总结)web安全 防止数据采集的几种方式
- Python 命令行工具 -- click
- [Multi]AutoCompleteTextView&Button
- iOS 崩溃日志 Backtrace的符号化