• 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: NSTableView & Multiple Columns
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView & Multiple Columns


  • Subject: Re: NSTableView & Multiple Columns
  • From: Graham Cox <email@hidden>
  • Date: Tue, 20 Jul 2010 19:49:59 +1000

On 19/07/2010, at 9:32 AM, Robb wrote:

> I'm trying to setup a table view with multiple columns, but I can't figure out how to identify any particular column.
> what does [tablecolumn identifier] actually return so i can compare it?  I assumed a string, but that didn't work.  So my questions is, what do I do with the NSTableColumn thats being passed to me?


Apart from the error that Quincey pointed out, matching table column identifiers to a property of your data model doesn't require a bunch of if..else..if..else statements. Use KVC, viz:

- (id) tableView:(NSTableView *) tv objectValueForTableColumn:(NSTableColumn *) tc row:(NSInteger) index
{
	id indexedObject = [[self arrayOfDataObjects] objectAtIndex:index];

	return [indexedObject valueForKey:[tc indentifier]];
}


You sometimes need to do some extra work for a particular table column, but by and large the above is nearly always all you need. Sometimes I think someone has actually designed this stuff to make life easy ;-)

Looking at your code, you appear to have three separate arrays of the same dimension holding individual properties. Instead, I would combine them into a single array holding objects with three separate properties. Create a custom NSObject subclass if needed. This will be far, far easier than trying to keep three arrays in step, which is not a professional design.

--Graham_______________________________________________

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

References: 
 >NSTableView & Multiple Columns (From: Robb <email@hidden>)

  • Prev by Date: Re: Help with canConcurrentlyReadDocumentsOfType:
  • Next by Date: Re: Basic Q: Where is the best place to open a drawer?
  • Previous by thread: Re: NSTableView & Multiple Columns
  • Next by thread: Help with canConcurrentlyReadDocumentsOfType:
  • Index(es):
    • Date
    • Thread