Problem using bindings with deep key paths
Problem using bindings with deep key paths
- Subject: Problem using bindings with deep key paths
- From: Gwynne Raskind <email@hidden>
- Date: Wed, 20 Jan 2010 09:06:42 -0500
This is most likely a very basic question, but I seem to be stumped just the same.
I have an application nib (MainMenu) set up such that it instantiates the NSApplication delegate and the application's main window.
The application delegate class has a property "player". The player is an instance of a class Player, which has as a property "track", which is (naturally enough) a Track object. Finally, the Track object has a property "info", which is again obviously an Info object.
The Player object is effectively constant; from a KVO perspective, it never changes over the course of the application. The Track object it contains changes often, and therefore the Info changes as well.
I created an NSObjectController at the top level of the nib, and connected its "content" outlet to the application delegate. I then created a second NSObjectController, and bound its "contentObject" binding to "selection.player" on the first controller. Repeat inwards until there are four controllers, one for each level of the above-described model objects. (This is not the natural configuration, but rather one of the variants I tried in the process of trying to make this work. The original configuration was a single object controller bound to the app delegate.)
Finally, I bound several views' "value" bindings to the controller for the Info object, with the appropriate model keys for the Info class, one of which is the aptly-named "title" (not to be confused with Sir Not Appearing In This Film). The full key path for the NSTextField in question is "selection.player.track.info.title", where selection is the app delegate.
It didn't work. The UI did not update with the values in the Info object for the given Track in the Player. I tried a couple dozen things, and finally found that the UI updated correctly when I generated a fake KVO notification for the "player" key in the application delegate.
It seems to me that this means that the object controller(s) are not observing the changes made to the various sub-objects of the application delegate. In other words, given the key path "player.track.info.title", any change to any key along that path is ignored unless "player" is considered to have changed as well. I've verified that all the accessors are fully KVC and KVO compliant (most are synthesized properties), and I've tried a long list of combinations of flags on the controllers and individual bindings.
Is this a design failure on my part, or am I trying to do something that bindings can't handle? To summarize, I want my UI to update any time I change the current Track object, which is contained by the "constant" Player object. This all worked very nicely and very neatly when I was using outlets and doing the KVO bits myself; the only issue I had with it then was that there were a whole lot of outlets on the application delegate...
(Note: The documentation on bindings is quite ancient (some of the screenshots are from 10.3's IB, for mercy's sake) and was completely unhelpful.)
-- Gwynne
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden