• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: dynamically adding and binding NSTableColumns
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamically adding and binding NSTableColumns


  • Subject: Re: dynamically adding and binding NSTableColumns
  • From: mmalcolm crawford <email@hidden>
  • Date: Sun, 7 Nov 2004 11:09:04 -0800

On Nov 7, 2004, at 10:25 AM, Jonathan 'Wolf' Rentzsch wrote:
mmalcolm crawford, email@hidden, wrote:
What am I doing wrong? I suspect it lies on the fact I'm using multiple
NSArrayControllers with a single NSTableView.
That could be it...  :-)
Dynamic addition/removal of table columns certainly does work if you
use a single array controller and key paths.  Is there any reason you
want to use multiple controllers?
Yes, since my data model is really just an array of columns, not an array
of rows (dictionaries). The columns are created and named by the user, so
there's really no key paths there to hook up. That is, I have columns of
strings, not rows of dictionaries.
I probably could hack something up using autogenerated key paths, but I
think I'd be fighting the design.


After a quick look --
I realize I'm being too abstract here, so here's my little working app
with source code:
<http://rentzsch.com/share/TruthTable-0.zip> (56K)

thanks, that helped! -- I *think* that actually autogenerated keypaths will be the way to make it work.

What I *think* should work would be to:

Create an array controller ("AC2") to manage the second table view.
For each new table column (TruthTableColumnModel), generate a new unique indentifier.
When you add the table column, bind its value to [AC2].arrangedObjects.identifier.


AC2's 'content' should be bound to, say, [TruthTableModel].tableValues

tableValues is an array of dictionaries, "faked" by indexed accessors.


- (unsigned int)countOfTableValues { return [[[columns objectAtIndex:0] entireCalculatedColumn] count]; // or however you want to calculate this... // [columns count] == 0 ? 0 : 2 ** [columns count]; ?? }

- (id)objectInTableValuesAtIndex:(unsigned int)index
{
	NSMutableDictionary *mDict = [NSMutableDictionary dictionary];

// iterate through identifiers, adding value of
[[(TruthTableColumnModel*)[aTableColumn identifier] entireCalculatedColumn] objectAtIndex:index];
// as value for key 'identifier'
}


I hope that sort of makes sense?

Conceptually you'll build up dictionaries containing appropriate key-value pairs for rows rather than columns.


An alternative, if possible, is to create your entire user interface in IB in advance, and
at runtime remove and cache those columns you don't need, adding them back as needed...
Yes. I read that advice on your excellent "Cocoa Bindings Examples and
Hints" page. It seemed kinda hacky, so I wanted to try a "pure" approach
first.


I prefer "pragmatic" (to "hacky")  :-)

I decided to just use an old-fashioned table data source, which works a
treat.

That may perhaps be the easiest solution in this case...

mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: dynamically adding and binding NSTableColumns (From: "Jonathan 'Wolf' Rentzsch" <email@hidden>)

  • Prev by Date: Re: dynamically adding and binding NSTableColumns
  • Next by Date: Re: Help: Odd crash, perhaps WebKit related
  • Previous by thread: Re: dynamically adding and binding NSTableColumns
  • Next by thread: Re: dynamically adding and binding NSTableColumns
  • Index(es):
    • Date
    • Thread