If you really implemented these methods in your spcAppDelegate.m file, you can double check that the Uses Data Source checked for NSComboBox in the nib file in Interface Builder:

Note that it was not installed by default in the quick scan project that I created. If you start without this check box, set the following command for the console when starting the application:
NSComboBox[2236:403] *** -[NSComboBox setDataSource:] should not be called when usesDataSource is set to NO NSComboBox[2236:403] *** -[NSComboBoxCell setDataSource:] should not be called when usesDataSource is set to NO
While the NSComboBox class reference is somewhat useful, when I first found out, I found that if there were helper manuals related to the class, they were much more useful in understanding how the class should be used in practice. If you look at the top of the link for the NSComboBox class in the Companion Guide , you will see Combo Box Programming Topics .
To set up a combo box that uses a data source, you can use something like the following:
spcAppDelegate.h:
spcAppDelegate.m:
#import "spcAppDelegate.h" @implementation spcAppDelegate @synthesize window; - (id)init { if ((self = [super init])) { comboBoxItems = [[NSMutableArray alloc] initWithArray: [@"Cocoa Programming setting the delegate" componentsSeparatedByString:@" "]]; } return self; } - (void)dealloc { [comboBoxItems release]; [super dealloc]; } - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox { return [comboBoxItems count]; } - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index { if (aComboBox == comboBox) { return [comboBoxItems objectAtIndex:index]; } return nil; } - (void)comboBoxSelectionDidChange:(NSNotification *)notification { NSLog(@"[%@ %@] value == %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [comboBoxItems objectAtIndex: [(NSComboBox *)[notification object] indexOfSelectedItem]]); } @end
Sample project: http://github.com/NSGod/NSComboBox .
NSGod
source share