grivescorbett
grivescorbett

Reputation: 1625

NSArrayController bindings without Core Data

I have an NSArrayController, the content of which I would like to be a list of the CGDirectDisplayIDs of all of the connected Screens. Right now I have the following code:

NSArray* screens = [NSScreen screens];
for (NSScreen* screen in screens)
{
    NSNumber* screenId = (NSNumber*)[[screen deviceDescription] valueForKey:@"NSScreenNumber"];
    [displaysList addObject:screenId];
}

[displaysArrayController setContent:displaysList];

displaysList is an NSMutable array which is allocated in awakeFromNib, what do I need to do in interface builder to populate a popup button with the values in displaysList?

Upvotes: 1

Views: 613

Answers (1)

lbrndnr
lbrndnr

Reputation: 3389

  1. In the class with the code you posted above add a new NSArray property. Call it for
    instance displaysArray
  2. Add a NSArrayController which you connect to the IBOutlet displaysArrayController
  3. In the Interface Builder you'll find a group called "Object Controller" Set its mode to "NSArray" Disable the check "Prepares Content"
  4. In another section you'll find a group called "Controller Content". Enable the checkbox and bind it to the object with the property displaysArray. Set the model key path to displaysArray.

I hope that helps :)

Upvotes: 1

Related Questions