iOS-NSNotification
来源:互联网 发布:快递称重扫描软件 编辑:程序博客网 时间:2024/05/22 16:49
NSNotification何时调用
前一阵子在维护一个项目时看到以前同事写的代码,看到他把所有的[[NSNotificationCenter defaultCenter] removeObserver:self];方法都放到了viewController的dealloc方法中,添加observer放到了init中,当时并没有想太多。
后来在写相关代码时发现,当某个notification被post之后,观察者的方法被多次调用。于是想到,难道是多次添加了观察者,而没有删除他?于是看了下苹果官方文档中的代码,发现官方例子中是在viewWillAppear的时候添加,viewWillDisappear的时候remove。
--------------
通知一件事件的改变会触发另一个事件[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myEvents:) name:UIKeyboardDidShowNotification object:nil];这个通知的意思是:当键盘出现的时候触发myEvents:这个事件
---------------
[[NSNotificationCenter defaultCenter] addObserver:self2 selector:@selector(execute:)3 name:@"NOTIFICATION_NAME"4 object:nil];
使用默认的通知中心,上面代码的意义的,观察者 self 在收到名为 @"NOTIFICATION_NAME" 的事件是执行 @selector(execute:),最后一个参数是表示会对哪个发送者对象发出的事件作出响应,nil 时表示接受所有发送者的事件。
0 0
- iOS-NSNotification
- ios-NSNotification
- iOS开发之NSNotification
- iOS NSNotification的使用
- ios NSNotification使用
- IOS 关于NSNotification
- iOS NSNotification的使用
- iOS NSNotification的使用
- iOS 消息通知-NSNotification
- iOS NSNotification的使用
- NSNotification 专注iOS开发
- iOS开发-通知NSNotification
- ios 通知NSNotification
- iOS NSNotification的使用
- iOS NSNotification的使用
- iOS NSNotification的使用
- iOS 通知 NSNotification
- iOS NSNotification的使用
- web开发html css js插件
- atoi,atol,strtod,strtol,strtoul实现类型转换
- LVS+Keepalived实现高可用集群
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 上海品牌策划方案要注意的几点技能
- iOS-NSNotification
- hadoop 各个工具原理
- 关于VNC登录的问题,连接只出现一个十字叉
- Android studio
- socket了解 一二
- string的size()和length()
- 阿斯达时代
- 设计模式C++实现(1)——工厂模式
- 理解正则表达式<前言>