Question

I've got an NSArrayController, and I'm using KVO to observe the Old/New values of it's selection method.

This works perfectly (triggers when the selection changes, the usual) except that the items in the change dictionary are all null instead of being the old/new selected object. [arrayController selection] still returns the proper object, but I'd like to be able to access the previously selected object as well if possible (my workaround will probably be to observe the selected index instead and see if that works).

The only possible reason for this I've come up with is perhaps it's because the NSArrayController is a proxy object.

So is this the expected behavior, or is something weird going on?

EDIT: I tried observing just the Indexes, but that didn't work either. Both old and new keys still show up as null.

Was it helpful?

Solution

mmalc's Cocoa bindings page says:

The change dictionary doesn't contain old and new values. This is not your fault, it's due to a bug in the controller. This bug will not be fixed in the forseeable future.

OTHER TIPS

For plain KVO (as opposed to bindings), try observing the selectedObjects property instead of the selection property. That will give you a straightforward array of objects instead of the proxy objects which are used by the Cocoa bindings system. I believe the old/new keys should accurately reflect the change in the selection that way.

Are you using NSKeyValueObservingOptionNew, and NSKeyValueObservingOptionOld in the options of addObserver:forKeyPath:options:context:?

If you could show us some code it would be helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top