问题描述
我正在使用KVO来获取NSArrayController的selectionIndex更改的通知
I'm using KVO to get notification of changes to NSArrayController's selectionIndex
[contoller addObserver:self forKeyPath:@"selectionIndex" options:NSKeyValueObservingOptionNew context:NULL];
,当我使用setSelectedObjects设置选择内容时:我收到有关selectionIndex更改的通知,这与我期望的一样.但是,当我尝试从更改字典中获取NSKeyValueChangeNewKey时,它总是返回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.
打印字典显示:
这是因为selectionIndex值是NSUInteger,不能放在字典中还是我做错了吗?
Is this because the selectionIndex value is a NSUInteger and can't be put in a dictionary or am I doing something wrong?
对我来说这不是问题,因为当我收到此通知时,可以通过其他方式从控制器中获取selectionIndex,我只是想知道为什么它没有达到我的预期.
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.
推荐答案
我在Lion 10.7.3上使用Xcode 4.2.1的10.6应用程序构建中看到了此行为.
I'm seeing this behaviour on a 10.6 app build with Xcode 4.2.1 on Lion 10.7.3.
将触发通知,但更改字典始终为NULL.
The notification fires, but the change dictionary is always NULL.
正如您所说,一旦触发通知,您就可以手动获取selectionIndex,因此对我的应用程序来说不是问题.
As you say, once you have the notification firing you can get selectionIndex manually, so not an issue for my app.
我在Google上搜索了一下,发现这是大约3年前的一个已知错误,所以也许它仍然存在吗?
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?
这篇关于KVO中的更改字典的selectionIndex始终包含NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!