On May 14, 2010, at 00:49, Andrew White wrote:

> I have an NSMutableSet of strings.  I update the set internally.  I want to 
> display a single column NSTableView with all the current strings in the set.  
> These strings can (and do) change as the program runs.  From a user 
> perspective, this is read-only: the user can't edit it.
> 
> And I want to do it with bindings.
> 
> I cannot for the life of me figure how to plumb it.  And how to get KVO to 
> work.

It's not clear which part of this is giving you trouble. There are basically 3 
parts to it:

1. Make the set of strings be a property of an object that you can bind to in a 
XIB file. That means, usually, either File's Owner (which is typically a 
NSDocument or NSWindowController subclass) or your application delegate, 
depending on where the strings are.

Arrange to always update this set KVO-compliantly. That is, don't change the 
set directly (except when creating it), but change the proxy returned by 
[object mutableSetValueForKey:].

2. Put a NSArrayController in your XIB file. Bind its contentSet binding to the 
set property from #1. (I always thought contentSet only worked for Core Data 
relationships, but I can't find any requirement for this in the NSArray 
controller documentation. If it throws an exception saying the array controller 
needs to be in entity mode, then you'll have to use an array instead of a set 
for the array controller content.)

You might want to bind the array controller to sort descriptors, too, if there 
is some ordering of the strings that you want. (Or, just work with an array 
that you maintain in the correct order, instead of a set.)

3. Bind the table column to the array controller's arrangedObjects. Leave the 
model key blank, or specify "self" if it complains. (This is a funky way to get 
to the strings, but it works so long as you don't try to edit them.)

That should be all you need.


_______________________________________________

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