NSNotificationCenter的几种基础用法
来源:互联网 发布:c语言闰年月份计算 编辑:程序博客网 时间:2024/05/21 10:57
除了用的比较多的delegate和block之外,还有就是通知。通知的功能比前面两种要强大的多,当然也不能随便滥用,否则,不知道会发生社么.
1.一般注册、发送通知
首先要注册通知
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(textViewChange) name:notificationNameobject:(id)object];
然后就是当需要通知别的类的时候就发送通知
[[NSNotificationCenter defaultCenter]postNotificationName:notificationName object:nil];
当然啦,注册和发送时的通知名必须要一样,object就是要给的数据啦
2、监听一些view的变化
例如:监听UITextField、UITextView文本框内length的变化
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textViewChange) name:UITextViewTextDidChangeNotification object:textView];
目前遇到也就这么两种.
0 0
- NSNotificationCenter的几种基础用法
- NSNotificationCenter以及app的几种运行状态
- NSNotificationCenter 用法 一个简单的使用 NSNotificationCenter 的代码例子
- NSNotificationCenter 用法
- NSNotificationCenter 用法
- NSNotificationCenter用法
- NSNotificationCenter几点说明
- NSNotificationCenter 的几篇值得收藏的网文
- NSNotificationCenter用法实例
- NSNotificationCenter用法总结
- NSNotificationCenter 用法总结
- NSNotificationCenter用法总结
- NSNotificationCenter用法总结
- NSNotificationCenter 用法详解
- NSNotificationCenter用法总结
- NSNotificationCenter用法总结
- NSNotificationCenter 用法注意点
- NSNotificationCenter用法总结
- 258. Add Digits
- UVa 1586 Molar mass (计算分子量,不含扩号)
- 自己装mysql的问题
- 剑指offer代码解析——面试题15求链表中倒数第K个结点
- 为什么要使用SLF4J而不是Log4J
- NSNotificationCenter的几种基础用法
- XILINX 内核下载
- 编译原理开篇
- Deploying my application at the root in Tomcat(转自StackOverFlow,做记录)
- Fragment的使用(二)
- ZOJ-3908-Number Game
- Libgdx介绍及环境安装
- springwebmvc教程
- Arrays和Array,Collections和Collection