コンボボックスのサンプルです。NSComboBoxクラスを主に使います。
主なメソッドは以下となります。
メソッド | 説明 |
---|---|
- (void)insertItemWithObjectValue:(id)anObject atIndex:(NSInteger)index | index で指定した位置に anObject で指定したオブジェクトを挿入 |
- (NSInteger)numberOfItems | ポップアップリストのItemの数 |
リストの最後に項目を追加する場合は以下の様に現在の項目数を取得して末尾に追加します。
[comboBox insertItemWithObjectValue:@"Red" atIndex:[comboBox numberOfItems]];
主な処理は以下の様になります。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [comboBox insertItemWithObjectValue:@"Red" atIndex:[comboBox numberOfItems]]; [comboBox insertItemWithObjectValue:@"Green" atIndex:[comboBox numberOfItems]]; [comboBox insertItemWithObjectValue:@"Blue" atIndex:[comboBox numberOfItems]]; } - (IBAction)changeSelectItem:(id)sender { NSLog(@"%@ に選択が変更されました\n", [comboBox stringValue]); }
公式の解説はこちら。
NSControl Class Reference
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSControl_Class/Reference/Reference.html
日本語の解説が良い人はこちらのSatoshi Oomoriさんのページを参照下さい。
http://www.oomori.com/cocoafw/ApplicationKit/NSComboBox/index.html
※注記
http://www.oomori.com/cocodesu/index.html