[Mac] NSArrayController の KVO通知の中身が nil になる(現象記録)
2010年12月20日月曜日 | Published in Cocoa Bindings, Mac OS X 10.6 | 2 コメント
NSTableView→NSArrayController→NSMutableArray とバインドしている状態でテーブルのカラムの値の変化を NSArrayControllerのKVO経由で取得してみた。
KVOの登録はこんな感じ。
既知の問題なのか仕様なのかわからない。ネットで探すと同じ現象が報告されていた。
cocoa - Observer properties of objects in an NSArrayController - Stack Overflow
KVO for NSArrayController subclass
ずいぶん昔からあるようなので仕様なのか?
- - - -
NSArrayController を対象に Undo機能を実装しようとしているが KVOが使えないので困っている。仕方がないので NSArrayController のサブクラスを作り対応しようとしているが今度は objectDidBeginEditing: の引数(実体が非公開のNSTextValueBinder)の扱いで困っている。編集前後のイベントは取れるが値が取得できない。うーむ。
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)の扱いで困っている。編集前後のイベントは取れるが値が取得できない。うーむ。
登録:
コメントの投稿 (Atom)
人気の投稿(過去 30日間)
-
公式リファレンスの Q&A に解説がある。 Technical Q&A QA1551: Detecting the start and end edit sessions of a cell in NSTableView. 方法は Delegate と Not...
-
2011年06月09日 追記 UITableViewCell の Identifier 設定を忘れてたので追記しました。 UINib を使うと簡単に Nib で定義した UITableViewCell が使える。 今回のサンプル: [関連] Cocoaの日々: [iO...
-
Asset Catalogには画像以外のデータも置ける。サウンドファイル(.aif)を置いてみた。 取り出すには NSDataAsset を使う。 let sound = NSDataAsset(name: name) // use sound.data 取り出したサウ...
-
パスワードを暗号化して安全に iPhone/iPad へ保管したい。iOS はこの用途の為に Keychain Services を提供している。今回は Keychain Services について調べてみた。リファレンスの内容に加え、独自に調査・検証した結果をまとめてある。動作...
-
Core Data を使ったアプリケーションで下のような検索機能を実装している。 設定された値を元に NSPredicate を作成し、Core Data に対して検索をかけるのだが、こういう場合に NSCompoundPredicate が役に立つ。 NSCompound...
Responses
匿名
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
なるほど。仕様のようですね。
情報どうも。
Leave a Response
[フレーム]