- 浏览: 438735 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (538)
- C/C++ Primer (69)
- Objective-C Primer (102)
- Python Primer (19)
- JavaScript Primer (1)
- Java Primer (37)
- PHP Primer (17)
- 泛 Linux (37)
- Shell Script (21)
- APUE (21)
- UNP__1&2 (19)
- NetWork (7)
- Oracle周边 (38)
- Mysql里边 (6)
- Windows技 (9)
- 简单算法 & 数据结构 (14)
- 设计模式 (6)
- GTK历程 (12)
- 工具使用 (25)
- 杂事 (23)
- 一些概念 (17)
- Web方面 (10)
- myCodeTools (9)
- ^未 竟$ (13)
- 硬件通信 (2)
- Games (1)
最新评论
http://blog.csdn.net/a6472953/article/details/7817538
http://www.cnblogs.com/pengyingh/articles/2383629.html
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#//apple_ref/doc/uid/10000177i
-------------------------------
cocoa的KVO模型中,有两种通知观察者的方式,自动通知和手动通知。
自动通知由cocoa在属性值变化时自动通知观察者,
手动通知需要在值变化时调用 willChangeValueForKey:和didChangeValueForKey:
通知调用者。为求简便,我们一般使用自动通知。
要使用手动通知,需要在 automaticallyNotifiesObserversForKey方法中明确告诉cocoa,哪些键值要使用自动通知:
http://www.cnblogs.com/pengyingh/articles/2383629.html
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#//apple_ref/doc/uid/10000177i
//注册监听 [mTextView addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew context:nil]; //处理属性改变事件 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { UITextView *mTextView = object; NSLog("the textView content is change!!"); }
-------------------------------
cocoa的KVO模型中,有两种通知观察者的方式,自动通知和手动通知。
自动通知由cocoa在属性值变化时自动通知观察者,
手动通知需要在值变化时调用 willChangeValueForKey:和didChangeValueForKey:
通知调用者。为求简便,我们一般使用自动通知。
要使用手动通知,需要在 automaticallyNotifiesObserversForKey方法中明确告诉cocoa,哪些键值要使用自动通知:
//重新实现NSObject类中的automaticallyNotifiesObserversForKey:方法,返回yes表示自动通知。 + (BOOL)automaticallyNotifiesObserversForKey:(NSString*)key { //当这两个值改变时,使用自动通知已注册过的观察者,观察者需要实现observeValueForKeyPath:ofObject:change:context:方法 if ([key isEqualToString:@"isFinished"]) { return NO; } return [super automaticallyNotifiesObserversForKey:key]; }
手动通知在需要改变值_isFinished变量的地方,使用 [self willChangeValueForKey:@"isFinished"]; finished = YES; [self didChangeValueForKey:@"isFinished"];
发表评论
-
float equal
2013-05-23 18:21 775- (BOOL)floatA:(float)f1 equalB ... -
Coding Guidelines for Cocoa
2013-05-17 16:53 629参考: https://developer.apple.com ... -
Cell
2013-05-16 14:32 745- (void)tableView:(UITableView ... -
Object-C编程规范
2013-05-15 10:49 6911.参考苹果的文档 “Coding Guidelines fo ... -
MacPorts
2013-02-28 18:12 568http://blog.csdn.net/lynjay/art ... -
ios Associative 扩展属性
2013-01-08 16:45 1491@dynamic和@synthesize http://blo ... -
ObjC Dynamic
2013-01-08 15:21 738原文:http://www.onevcat.com/2012/ ... -
UITableView & UITextField
2012-11-08 00:35 788keyboard event ---------------- ... -
UIWebView
2012-10-24 11:06 711http://hi.baidu.com/wei_1123/it ... -
Device orientation
2012-10-15 16:20 693- (BOOL)shouldAutorotateToInter ... -
system notification
2012-10-12 15:22 588for UIApplication These notifi ... -
NSZombies
2012-08-09 08:51 626NSZombies搞定EXC_BAD_ACCESS http: ... -
Quartz 2D Programming Guide
2012-07-17 00:51 552Quartz 2D 内容不少啊 Graphics Trans ... -
NSCache
2012-07-12 14:25 710http://thenewself.blog.163.com/ ... -
NSCoding
2012-07-12 13:39 913@protocol NSCoding - (void ... -
分析 crash 报告的方法
2012-07-12 01:15 546http://blog.csdn.net/toss156/ar ... -
Multi-touch
2012-07-11 23:33 687智能与灵活与工作量>_< http://www.o ... -
iOS的多核编程和内存管理
2012-07-11 18:14 678http://anxonli.iteye.com/blog/1 ... -
NSCopying
2012-07-10 15:54 481http://www.apple.com.cn/develop ... -
NSTimeZone
2012-07-10 14:42 390http://developer.apple.com/libr ...
相关推荐
使用KVC对属性赋值 使用KVC对属性取值 KVC对数组取值 KVO是key value observing, 它是一种非常重要的机制,允许监听属性值的变化
关于ios学习中的通知和kvc,kvo案例的整理,基础的oc学习
已经拥有一年经验的你真的了解KVC,KVO吗?也许不!以前我以为自己都有上架项目,这都是太基础的东西,但今天我重新回头看了以前做的笔记,真的是书读百遍,其义自见。
KVC 与 KVO 使用姿势和原理解析
KVC、kVO原理详解
iOS中KVC-KVO例子,
自己练习swift时做的KVC和KVO的案例,供初学者使用
但需要注意的是,键值观察(KVO)是建立在键值编码(Key Value Coding,简称KVC)的基础上,也就是说任何你想使用KVO观察的属性必须符合键值编码。 这个demo主要以字符串、数组为例来学习键值编码和键值观察。 ...
相信通过这个工程可以让初学者更好的理解iOS的kvc和kvo模式,如果有需要相关文档的可以留言给我。
这里是我看别人博客写的kvc与kvo,自己写的代码,本来不打算收费,但是找不到免费的按钮在哪,所以就选了最小的资源分数1.
性的监听,参见探索KVC/KVO的实现原理KVC 一 和 探索KVC/KVO的实现原理KVO 二 虽然 iOS 提供了对对象属性的观察者模式机制,但想想很多 Android 同学们应该不会在意。这不是很容易么,我 分分钟也能写一个
【Debugging Tips, Searching, Notifications, KVC,KVO】[PDF] [iPhone/iPad/iOS]
KVC 是基于OCRuntime机制,Runtime机制里面可以通过得到实例变量并且访问其私有的成员变量区;实现keyPath中的访问能力;KVO一种通知发送机制,实现一对多,多对一的映射关系
详细的介绍了KVO与KVC的原理机制,可以有效运用KVO-KVC编程
与博客配套的KVC KVO代码,博客地址http://blog.csdn.net/liuyinghui523/article/details/77885198 简单的总结
一个kvo 的demo,kvo的用法。kvc/kvo的用法
本文档主要是针对KVC和KVO的使用方法的一些总结,希望对大家有所帮助。
代码仅供参考 #import "lgsAppDelegate.h" #import "Student.h" #import "Teacher.h" @implementation lgsAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:...
SimpleMVVM 是一个简单的 Objective-C 的 MVVM 例子,使用单件 和 KVC/KVO。 标签:SimpleMVVM
KVC_KVOTest Demo代码 KVC KVO IOS 观察者 Observe