NSPopUpButton に NSString の配列を設定したいと考えています。また、選択した項目を 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