Binding NSPopUpButton to an NSMutableArray

My view controller has this property:

@property NSMutableArray *tableCities;

Whenever I press a button a new city object is added to this array, it consists of a dictionary of NSStrings containing the name and state of the city being added.

Now, I have an NSPopUpButton that I'd like to bind to the city name of all cities in this NSMutableArray, how exactly can I achieve this with the Bindings Inspector?

Hi @that_aint_it_chief , well this question about Mac OS brings me to all past days on I started developing on a Macintosh || Classic with Borland C and Inside Macintosh :)

Try to help you, I think that you should use this bindings from inspector tab:

  1. Bind Content -> yourViewControllerClass
  2. ControllerKey -> tableCities

If for example you should have some more structured model (for example an array of objects with field title for example), then you should use something like this:

  1. Bind Content Values -> yourViewControllerClass
  2. ControllerKey -> arrangedObjects
  3. Model Key Path: title

Here documentation on bindings

https://developer.apple.com/library/archive/documentation/Cocoa/Reference/CocoaBindingsRef/BindingsText/NSPopUpButton.html

Bye Rob

I'm not finding these options, I will describe the situation in more detail here:

My ViewController has the PopUpButton:

// ViewController.h
@interface ViewController : NSViewController<NSWindowDelegate, NSTableViewDataSource,
NSTableViewDelegate>

@property (weak) IBOutlet NSPopUpButton*	popUpButton;
// ...
@end

Then I tried to add some object to the tableCities:

NSString* newCity = @"test";

    
    NSString* filePath = @"/Users/eagle/Documents/cities/denver.jpeg";
    NSDictionary *obj = @{@"image": [[NSImage alloc] initByReferencingFile:filePath],
                          @"name": newCity,
                          @"filePath": filePath
    };


[_tableCities addObject: obj];

I just wanted my pop up button to reflect the contents of _tableCities, specifically the "@name" field.

Going back to the story board in the bindings inspector, selecting the "Bind to View Controller" checkbox makes the "Controller Key" grayed out, what gives?

Sorry if this is a dumb question but I can't for the life of me get this to work .

Binding NSPopUpButton to an NSMutableArray
 
 
Q