NSArrayController bindings without Core Data
I have an NSArrayController, the content of which I would like to be a list of the CGDirectDisplayID
s 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"];
[d开发者_开发问答isplaysList 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
?
- In the class with the code you posted above add a new NSArray property. Call it for
instance displaysArray - Add a NSArrayController which you connect to the IBOutlet displaysArrayController
- In the Interface Builder you'll find a group called "Object Controller" Set its mode to "NSArray" Disable the check "Prepares Content"
- 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 :)
精彩评论