KVO 中的更改字典对于选择索引始终包含 NULL
我使用 KVO 来获取 NSArrayController 的选择索引更改的通知
[contoller addObserver:self forKeyPath:@"selectionIndex" options:NSKeyValueObservingOptionNew context:NULL];
,并且当我使用 setSelectedObjects: 设置选择时,我会收到选择索引按预期更改的通知。但是,当我尝试从更改字典中获取 NSKeyValueChangeNewKey 时,它总是返回 NULL。
打印字典显示:
{ 种类=1; 新=“”; }
是因为 SelectionIndex 值是 NSUInteger 并且不能放入字典中还是我做错了什么?
这对我来说不是一个问题,因为当我收到此通知时,我可以通过其他方式从控制器获取选择索引,我只是想知道为什么它没有按照我的预期进行。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 Lion 10.7.3 上使用 Xcode 4.2.1 构建的 10.6 应用程序中看到了这种行为。
通知触发,但更改字典始终为 NULL。
正如您所说,一旦您触发了通知,您就可以手动获取选择索引,所以这对我的应用程序来说不是问题。
我用 Google 搜索了一下,发现这是大约 3 年前的一个已知错误,所以也许现在仍然如此?
http://www.cocoabuilder .com/archive/cocoa/231886-problem-observing-selectionindex-of-an-array-controller.html
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