NSPopUpButton binding question

Discussion in 'Mac Programming' started by Spraystarch, Jul 23, 2008.

  1. Spraystarch macrumors newbie

    Joined:
    Jul 23, 2008
    #1
    I'm hoping that I'm just stupid and this is actually a simple problem, but I can't figure it out. Here's my situation:

    I've got an NSArrayController whose datasource is an array of Coin objects. Each Coin has various attributes, each of which is bound to a column of an NSTableView. However, I don't want my table to be editable, so for each instance variable of the Coins, I've got an editable NSTextField also bound to the appropriate key of the selected object in the table. In this way, the table lets me see the objects, but to edit one I select it and use the text fields. Pretty standard stuff.

    One of the instance variables (NSString *mint) of the Coin class is unique in that it should only ever take one of three specific values ("Philadelphia," "Denver," or "San Francisco"), so instead of using a text field to edit this one, I'd like to have a pop up button from which the user can select the appropriate mint location. Each new Coin is initialized with Philadelphia as its mint.

    I've read the Apple documentation on NSPopUpButton bindings, but I can't make heads or tails of it. I'd be really grateful if someone could point me in the right direction here.
     
  2. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #2
    Try this to see if it works.

    You could add an NSPopUpButton, change the "item x" to "city name", give each menuitem an unique tag number and work based on the tag number. For example tag "1" is "city 1", etc. Instead of NSString *mint, you have NSNumber *mint. Then bind selectedTag of your popupbutton to mint.
     

Share This Page