Re: dynamically adding NSTableColumns while using bindings
Re: dynamically adding NSTableColumns while using bindings
- Subject: Re: dynamically adding NSTableColumns while using bindings
- From: "I. Savant" <email@hidden>
- Date: Wed, 1 Aug 2007 16:26:41 -0400
On 8/1/07, Paul Gribble <email@hidden> wrote:
> So I have figured out from the various demo code, etc, how to use
> KVC-compliant setters and getters in myDocument.m, which enables me very
> easily, with very little code, to implement a NSTableView, use bindings to
> bind each NSTableColumn to an NSArrayController, and bind each
> NSArrayController to an NSMutableArray instance variable in myDocument.m.
This seems wrong. Why do you need an array controller for each
separate column? Typically your (single) array controller would be
bound to some collection (like your Document's "people" array, for
example). Each column's value would be bound to your array
controller's "arrangedObjects.field" where "field" represents some
KVC-compliant property (such as "firstName", "lastName", "age", etc.).
So, "arrangedObjects.firstName" would be a typical key.
If you have some specific reason to use more than one array
controller, you should be able to communicate it clearly. If you
can't, then you probably should be using only one array controller for
your table.
> Here's my question: What if I want the user to be able to dynamically add or
> remove columns? How do I set things up using bindings so that when the user
> clicks "add column", a new column appears, is bound to a new nsarray
> controller, which is turn bound to a new NSMutableArray in myDocument.m? I
> guess what I need in myDocument.m is an NSMutableArray (or maybe
> NSMutableDictionary?) that in turn stores NSMutableArrays, one for each
> NSTableColumn? But then I'm at sea when it comes to how to set this all up
> with bindings.
If you *must* use more than one array controller, I'd keep an array
of array controllers and add new / remove old ones as needed. At the
same time create, bind, and add new columns to, or unbind and remove
old columns from your table view.
Otherwise, use *one* array controller, create an outlet with which
to communicate with it (such as peopleArrayController) and
create/bind/add a new column to the table (using your outlet
"peopleArrayController" to establish the binding) or unbind/remove
table columns as needed.
--
I.S.
_______________________________________________
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