• 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: Steven Kramer <email@hidden>
  • Date: Sun, 7 Nov 2004 18:31:19 +0100


Don't take my word for it, but I'm pretty sure you can't do this. All your columns have to be bound to the same array controller.


Regards

   Steven

Op 7-nov-04 om 16:45 heeft Jonathan 'Wolf' Rentzsch het volgende geschreven:

I have a columnar data model. That is, while each column always has the
same number of rows as its peer columns, other than that each column is
rather stand-alone.

I'm creating my columns at runtime based on user-entered data. I thought
I could just allocate NSTableColumns as I need them, create an
NSArrayController and bind them up.


This works when I have just one column, but fails as I add more.

Here's the repro, with the entire compiled project at
<http://rentzsch.com/share/DynamicTableColumnSpike.zip> (60K):

Imagine an empty (NSTableColumn-less) NSTableView, bound to an IBOutlet
named `tableView`. Here's my code to dynamically add a column:

- (IBAction) addColumnAction:(id)sender {
// Create and add a column.
NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:nil]
autorelease];
[tableView addTableColumn:column];


  // Create an array controller, bind it to sample data
  // and then bind the column to the controller.
  NSArrayController *controller = [[[NSArrayController alloc] init]
autorelease];
  [controller setContent:[NSArray arrayWithObjects:@"one", @"two",
@"three", nil]];
  [column bind:@"value" toObject:controller
withKeyPath:@"arrangedObjects" options:nil];
}

The first time you add a column, the NSTableView ends ups looking like
this:

+-------+
| Field |
+-------+
| one   |
| two   |
| three |
+-------+

But if you add another column, executing the same code, it ends up
looking like this:

+-------+-------------------+
| Field | Field             |
+-------+-------------------+
| one   | (one, two, three) |
| two   | (one, two, three) |
| three | (one, two, three) |
+-------+-------------------+

And then continues on, as you add more columns:

+-------+-------------------+-------------------+
| Field | Field             | Field             |
+-------+-------------------+-------------------+
| one   | (one, two, three) | (one, two, three) |
| two   | (one, two, three) | (one, two, three) |
| three | (one, two, three) | (one, two, three) |
+-------+-------------------+-------------------+

What am I doing wrong? I suspect it lies on the fact I'm using multiple
NSArrayControllers with a single NSTableView. Usually you just use one
across multiple NSTableColumns, relying on the binding's key path to get
specific data into a column.



-- email@hidden http://sprintteam.com/

_______________________________________________
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: 
 >dynamically adding and binding NSTableColumns (From: "Jonathan 'Wolf' Rentzsch" <email@hidden>)

  • Prev by Date: Re: dynamically adding and binding NSTableColumns
  • Next by Date: Re: dynamically adding and binding NSTableColumns
  • Previous by thread: Re: dynamically adding and binding NSTableColumns
  • Next by thread: Re: dynamically adding and binding NSTableColumns
  • Index(es):
    • Date
    • Thread