作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的.注册通知:即要在什么地方接受消息 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(...
分类:
其他好文 时间:
2015-04-17 17:34:02
阅读次数:
75
/** 在应用委托的方法didFinishLaunchingWithOptions中添加*/[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kRe...
分类:
其他好文 时间:
2015-04-13 18:32:43
阅读次数:
111
NSNotificationCenter是IOS中常用的消息通知机制,不过在使用过程中有几点需要注意的问题.直接贴Apple 的官方文档吧:A notification center delivers notifications to observers synchronously. In othe...
分类:
其他好文 时间:
2015-04-11 22:23:58
阅读次数:
148
一,在需要的地方添加监听[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardWillShowNotification:) ...
分类:
移动开发 时间:
2015-04-10 17:00:56
阅读次数:
167
iOS-单例模式
何为单例模式,就是说如果在一个应用程序中,如果你想让一个类的实例使用的都是同一个,这时你就把该类设置为单例模式,iOS基础框架中有很多的单例模式类,如NSUserDefault,NSNotificationCenter等都是单例模式的设计。
单例模式的设计准则:
1.通过类方法获取单例实例,
2.必须是原子性的,保证多线程的访问安全
...
分类:
移动开发 时间:
2015-04-02 20:55:31
阅读次数:
209
最近在做的项目需要cell里面的数据需要和后台实时交互。而collectionview reload会整体刷新。//m层 发送通知[[NSNotificationCenter defaultCenter]postNotificationName:@"CartProUpdate" object:sel...
分类:
Web程序 时间:
2015-04-02 06:37:14
阅读次数:
269
首先注册通知如下:
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "keyboardWillShow:", name:
UIKeyboardWillChangeFrameNotification, object:
nil)
通知内容:
func...
分类:
移动开发 时间:
2015-04-01 11:25:58
阅读次数:
213
* 一个文本输入框的文字发生改变时,文本输入框会发出一个UITextFieldTextDidChangeNotification通知* 因此通过监听通知来监听文本输入框的文字改变[[NSNotificationCenter defaultCenter] addObserver:self select...
分类:
其他好文 时间:
2015-04-01 00:16:28
阅读次数:
249
观察者设计模式详解观察者设计模式详解
基本概念
NSNotificationCenter的使用
添加监听
接收消息
删除监视
KVO的使用
基本概念
注册观察者
观察者对象发生变化时的回调方法
remove观察者身份
代码实现基本概念观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己.而在IOS开发...
分类:
移动开发 时间:
2015-03-31 18:10:48
阅读次数:
209
NSNotificationCenter(通知中心)【注意】需再dealloc中移除观察者获取通知中心单例对象 NSNotificationCenter *center=[NSNotificationCenter defaultCenter];常用方法: 1.注册观察者 - (void)add...
分类:
其他好文 时间:
2015-03-30 22:51:05
阅读次数:
184