我想用一组 NSStrings 填充 NSPopUpButton。我还希望能够在 NSPopUpButton 中设置所选项目并获取所选值。有没有办法使用绑定来做到这一点?这就是我所拥有的,只有绑定到 arragedObjects 的数组控制器的内容。
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
    NSMutableArray *myArray;
    IBOutlet NSPopUpButton *myPopUpButton;
    IBOutlet NSArrayController *processArrayController;   
}
@property (assign) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
     NSString *firstObject = @"Lustre";
     NSString *secondObject = @"TwoTone Laser";
     NSString *thirdObject = @"Laser Mark";
     NSString *forthObject = @"Double Lustre";
     NSString *fifthObject = @"CG Ink";
    // Create the array
     myArray = [[NSMutableArray alloc] initWithObjects:firstObject, secondObject,  
     thirdObject, forthObject, fifthObject, nil];
    // Sort the array
    [myArray sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
    // Set contents of the array controller that is bound to the popup button
    [processArrayController setContent:myArray];
    // Set a selection to an item of the popup button
    [myPopUpButton  selectItemWithTitle: firstObject];  
}
@end