• 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: NSPopUpButton Binding Frustration
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPopUpButton Binding Frustration


  • Subject: Re: NSPopUpButton Binding Frustration
  • From: Ken Thomases <email@hidden>
  • Date: Mon, 30 Jan 2012 10:26:05 -0600

On Jan 30, 2012, at 12:32 AM, Seth Willits wrote:

> Say I have a file type popup in a save sheet for saving an image:
>
> @property NSString * fileType;
>
> - (NSArray *)fileTypes
> {
> 	return [NSArray arrayWithObjects:(id)kUTTypeJPEG, (id)kUTTypePNG, (id)kUTTypeTIFF, nil];
> }
>
> - (NSArray *)fileTypeNames
> {
> 	return [NSArray arrayWithObjects:@"JPEG", @"PNG", @"TIFF", nil];
> }
>
> The popup should display the names, but I want the selected item bound to fileType which is one of the UTIs. By my reading of the documentation, this _should be very simple_.
>
> Bind:
> content -> fileTypes*
> contentValues -> fileTypeNames
> selectedObject -> fileType

The contentValues and contentObjects, if bound, must be bound to an extension of the key path that content is bound to.  It doesn't work with two separate arrays like that.

You can make fileTypes an array of dictionaries, where each dictionary has a "uti" key and a "displayName" key.  Then, you can bind like so:

content -> fileTypes
contentValues -> fileTypes.displayName
contentObjects -> fileTypes.uti
selectedObject -> fileType

The purpose of the contentObjects binding is so that the selectedObject gets the UTI string and not the dictionary from the fileTypes array (i.e. the value from the content binding).  If you're fine with having it be the dictionary, you don't have to bind contentObjects.

Regards,
Ken


_______________________________________________

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: NSPopUpButton Binding Frustration
      • From: Seth Willits <email@hidden>
References: 
 >NSPopUpButton Binding Frustration (From: Seth Willits <email@hidden>)

  • Prev by Date: Re: Subclassing IKImageView
  • Next by Date: Re: NSPopUpButton Binding Frustration
  • Previous by thread: Re: NSPopUpButton Binding Frustration
  • Next by thread: Re: NSPopUpButton Binding Frustration
  • Index(es):
    • Date
    • Thread