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

NSPopUpButton Binding Frustration


  • Subject: NSPopUpButton Binding Frustration
  • From: Seth Willits <email@hidden>
  • Date: Sun, 29 Jan 2012 22:32:10 -0800

This is such a dead simple problem that I think I've encountered a couple times over the years and I don't think I've managed to ever find a solution that works how I want. I'll break this down into an easy specific example.


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


So content provides the list of objects, contentValues provides the corresponding titles for each object, selectedObject determines which object is selected. Sounds simple, never works. I've never been able to figure it out. It seems that if contents provides an array of *strings*, those strings are use as the titles *no matter what*.

The documentation for content says: "Unless contentValues is also bound, the titles of the items in the NSPopUpButton are derived by invoking description for each of the content objects," the documentation for contentValues says "An array of strings that are displayed as the items in the NSPopUpButton,"  but no matter what on earth I try, it will not work. If I have content bound to, say, an array of dictionaries, the popup uses contentValues to display the titles.


So what gives? This should be dead simple and for the life of me I can't figure it out.

Thanks.



*(The docs say content should be bound to an "array controller" — Not sure why it says that. An array appears to work the same as an array controller when I try it. I've tried creating an array controller bound to fileTypes and binding the popup's content to the ac.arrangedObjects but it still doesn't change the title situation.)


--
Seth Willits




_______________________________________________

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: Keary Suska <email@hidden>
    • Re: NSPopUpButton Binding Frustration
      • From: Ken Thomases <email@hidden>
    • Re: NSPopUpButton Binding Frustration
      • From: Quincey Morris <email@hidden>
  • Prev by Date: iCloud On OSX - Cannot save changes
  • Next by Date: Re: NSPopUpButton Binding Frustration
  • Previous by thread: Re: iCloud On OSX - Cannot save changes
  • Next by thread: Re: NSPopUpButton Binding Frustration
  • Index(es):
    • Date
    • Thread