KVOの登録はこんな感じ。
[_userArrayController addObserver:self
forKeyPath:@"arrangedObjects.title"
options:NSKeyValueObservingOptionOld|
NSKeyValueObservingOptionNew|
NSKeyValueObservingOptionInitial|
NSKeyValueObservingOptionPrior
context:nil];カラムの編集前後で下記が呼び出される。- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
:
}change を見ると変更前後の値が共に nil になっていて値が取得できなかった。[81129:a0f] change={
kind = 1;
new = <null>;
old = <null>;
}既知の問題なのか仕様なのかわからない。ネットで探すと同じ現象が報告されていた。
cocoa - Observer properties of objects in an NSArrayController - Stack Overflow
forKeyPath:@"arrangedObjects.name" forKeyPath:@"contentArray.name" forKeyPath:@"content.name" forKeyPath:@"selection.name" forKeyPath:@"selectedObjects.name"いろんな keyPathを試しているようだが駄目っぽい。
KVO for NSArrayController subclass
ずいぶん昔からあるようなので仕様なのか?
- - - -
NSArrayController を対象に Undo機能を実装しようとしているが KVOが使えないので困っている。仕方がないので NSArrayController のサブクラスを作り対応しようとしているが今度は objectDidBeginEditing: の引数(実体が非公開のNSTextValueBinder)の扱いで困っている。編集前後のイベントは取れるが値が取得できない。うーむ。



匿名
2010年12月27日 13:57
Important: The Cocoa bindings controller classes do not provide change values when sending key-value observing notifications to observers. It is the developer’s responsibility to query the controller to determine the new values.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Articles/ControllerKey-ValueObservingCompliance.html%23//apple_ref/doc/uid/TP40002493-SW1
匿名
2010年12月27日 13:57
Important: The Cocoa bindings controller classes do not provide change values when sending key-value observing notifications to observers. It is the developer’s responsibility to query the controller to determine the new values.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Articles/ControllerKey-ValueObservingCompliance.html%23//apple_ref/doc/uid/TP40002493-SW1
xcatsan says:
2010年12月27日 15:37
なるほど。仕様のようですね。
情報どうも。
xcatsan says:
2010年12月27日 15:37
なるほど。仕様のようですね。
情報どうも。