• 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 & URLs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPopupButton & URLs


  • Subject: Re: NSPopupButton & URLs
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 27 Dec 2009 14:47:36 -0600

On Dec 27, 2009, at 12:01 PM, Jeremy Matthews wrote:

> Currently, I have a nspopupbutton with some general values "Airbus", "Southwest", "Delta", etc...upon making the proper selection and clicking the "generate" button, it creates the event with said attributes, including the URL. So, I have a list of about 10 items in that popup, and a loooong if statement. Depending on the selectedItem of the nspopupbutton, it grabs the associated url and stuffs it into the method and returns the event.
>
> Normally, I'd take a switch/case approach here, but I've been warned about doing so in Cocoa.
>
> Any ideas?
> It works fine now, but I know that there has to be a more graceful approach.

This is a job for -[NSMenuItem representedObject].  Set a represented object for the menu items in the menu associated with the pop-up button.  The represented object can be anything you like.  It can be just an NSURL.  If you need multiple pieces of data associated with each menu item, the represented object can be a dictionary.

Cheers,
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 & URLs
      • From: Seth Willits <email@hidden>
References: 
 >NSPopupButton & URLs (From: Jeremy Matthews <email@hidden>)

  • Prev by Date: Re: Removing the dragging image
  • Next by Date: Re: NSPopupButton & URLs
  • Previous by thread: Re: [Cocoa-students] NSPopupButton & URLs
  • Next by thread: Re: NSPopupButton & URLs
  • Index(es):
    • Date
    • Thread