• 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 with PopUpButtonCell column with different content per row
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView with PopUpButtonCell column with different content per row


  • Subject: Re: NSTableView with PopUpButtonCell column with different content per row
  • From: Jerry Krinock <email@hidden>
  • Date: Thu, 18 Feb 2010 16:13:04 -0800

On 2010 Feb 18, at 13:30, Quincey Morris wrote:

> you could simply have your window controller provide an array property with version strings for the current OS (along with a KVO dependency to keep the property in sync with the current OS), and bind the popup content to that array.
>
> However, I'd suggest that perhaps you're asking the wrong question -- there might be a deeper data model design issue.

Quincey's answer is excellent, and abstract.  Let me give you a concrete example from one of my projects.  Presumably your table is bound to an array controller whose contentSet or contentArray is bound to a collection of Foo objects in your data model.

Table Column Bindings for "OS Version" column:

Content:
  Bind to: FooArrayController
  Controller Key: arrangedObjects
  Model Key Path: osVersionChoices

Content Values:
  Bind to: FooArrayController
  Controller Key: arrangedObjects
  Model Key Path: osVersionChoices.osVersionDisplayName

Selected Object:
  Bind to: FooArrayController
  Controller Key: arrangedObjects
  Model Key Path: osVersion

In your data model,

@interface Foo {
}

@property (retain) NSString* osVersion ; // Could also be NSNumber

/* Returns an array of NSStrings (or NSNumbers) */
- (NSArray*)osVersionChoices ;

...

@end

And finally, and I forgot who it was who gave me this invaluable tip, you implement a category on NSString (or NSNumber) which defines -osVersionDisplayName.  You can do your localization or transforming in here.  I've never been able to get a Value Transformer to work in an NSTableColumn binding.  But the category works every time.

Note that -osVersionChoices and of course -osVersionDisplay name are readonly.  No problem.  If you table is not editable, -osVersion can be readonly too.

_______________________________________________

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

  • Follow-Ups:
    • Re: NSTableView with PopUpButtonCell column with different content per row
      • From: "Sean McBride" <email@hidden>
References: 
 >NSTableView with PopUpButtonCell column with different content per row (From: "Sean McBride" <email@hidden>)
 >Re: NSTableView with PopUpButtonCell column with different content per row (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: NSTableView with PopUpButtonCell column with different content per row
  • Next by Date: Re: Hillegass printing challenge
  • Previous by thread: Re: NSTableView with PopUpButtonCell column with different content per row
  • Next by thread: Re: NSTableView with PopUpButtonCell column with different content per row
  • Index(es):
    • Date
    • Thread