On Sep 21, 2009, at 6:20 AM, Graham Cox wrote:

So, I have objects that can be selected. None, one or many objects might be in the selection. The current selection is available as an array property in the base controller (NSWindowController subclass) of this particular UI. Each selected object has a dictionary of associated data. It is this data I wish to edit via a table view with columns for keys and values. This seems like a perfect fit for NSDictionaryController. Where I'm having trouble is understanding how to deal with multiple selections (that is, multiple dictionaries presented by the main selection, not multiple selections in the table view - in fact the table view selection is largely unused). If there is a single selection, all well and good - looks like NSDictionaryController is a good fit out of the box. But for multiple selections, I'm less clear. I do need to be able to present in the UI effectively a merger of all the selected dictionaries, with all keys shown across the selection. Where multiple objects have the same key, this is one table row, either showing <multiple values> in the value column for that row, or the value if it's the same for all objects. Editing the value sets the values against that key for all objects, including adding that key/value to dictionaries for selected objects that currently lack it. I'm sort of thinking that I need two controllers, a bit like the Attacker/Weapon example in the documentation - but I can't be sure because not enough stuff is clear in my head, and besides, all the actual selection code is handled externally - I just have a -selection property returning the objects.

Bindings don't handle aggregate/coalesce. You will need to do that yourself in the main or a mediating model. Observe the controller's selection (or table view notifications) to update on the fly.

If I can progress on the first part, the next problem is representing the data type of the key/value pair. A given key will be associated with a definite data type - string, integer, real or boolean value. Ideally I'd like to add the appropriate cell type to the table row for the 'type' column. My current classically implemented UI doesn't do this at all, so this would be a new feature. It's very similar to the tables displayed by the plist editor application. Looking at NSDictionaryController it seems as if the only thing I can do for added values is set a string using - setInitialValue:, so I'm not sure how to handle the different data types.

Also not a bindings-supported behavior. Implement table view delegate methods to provide cells on the fly. You can apply formatters or transformers to force default values (if you can't do that at the model level).

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to