Change dictionary in KVO always contains NULL for selectionIndex

不羁岁月 提交于 2019-12-01 22:08:21

问题


I'm using KVO to get notification of changes to NSArrayController's selectionIndex

[contoller addObserver:self forKeyPath:@"selectionIndex" options:NSKeyValueObservingOptionNew context:NULL];

and when I set the selection using setSelectedObjects: I get notified of selectionIndex changing as I expect. However when I try to get NSKeyValueChangeNewKey from the change dictionary it always returns NULL.

Printing the dictionary shows:

{ kind = 1; new = ""; }

Is this because the selectionIndex value is a NSUInteger and can't be put in a dictionary or am I doing something wrong?

It's not such a problem for me as I can get the selectionIndex from the controller through other means when I get this notification, I'd just like to know why its not doing what I expected.


回答1:


I'm seeing this behaviour on a 10.6 app build with Xcode 4.2.1 on Lion 10.7.3.

The notification fires, but the change dictionary is always NULL.

As you say, once you have the notification firing you can get selectionIndex manually, so not an issue for my app.

I Googled around a bit and found that this was a known bug back about 3 years ago or so, so perhaps it still is?

http://www.cocoabuilder.com/archive/cocoa/231886-problem-observing-selectionindex-of-an-array-controller.html



来源:https://stackoverflow.com/questions/5784886/change-dictionary-in-kvo-always-contains-null-for-selectionindex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!