Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

klkittel

macrumors newbie
Original poster
Nov 10, 2011
12
0
Hello,

I followed the reference guide to NSComboBoxes, but my example ComboBox is empty, here is my code extracted from an NSWindowController:

Code:
- (void)windowDidLoad
{
	NSLog(@"New Phrases Window did load\n");
	
	// Load Data into Combo Boxes
	
	[actionField addItemWithObjectValue:@"1"];
	[actionField addItemWithObjectValue:@"2"];
	[actionField addItemWithObjectValue:@"3"];	
	[actionField setStringValue:@"Red"];
	
}
The message is printed, but the combobox is empty. What am I missing?
 
Last edited by a moderator:
OK, I've made a Combo Box in my main Window and the code above works. That leads me to believe that I haven't built my second window correctly or haven't done something correctly in interface builder. All my code for the combo box is the same between the two .h files and the connections were set up the same in interface builder.
 
Here is how I set up and display the window:

From the main window:
Code:
- (IBAction)newPhraseWindow:(id)sender
{
    winController = [[newPhraseWindowController alloc] init];
    [winController showWindow:self];
}
From the WindowController:

I moved the calls to initilize the combobox to init:
Code:
- (id)init
{
    self=[super initWithWindowNibName:@"newPhraseWindow"];
    if(self)
    {
		NSLog(@"New Phrases Window Init\n");
		
		// Load Data into Combo Boxes
		
		[actionField addItemWithObjectValue:@"1"];
		[actionField addItemWithObjectValue:@"2"];
		[actionField addItemWithObjectValue:@"3"];	
		[actionField setStringValue:@"Red"];
		
    }
    return self;
The window shows up, so I can't see where any of this code is at fault, but the combo box remains blank.
 
Last edited by a moderator:
Doing this in init is too early. In init, actionField won't yet be connected to the combo box. I assume you have connected the combo box to the actionField IBOutlet in the .xib

Trying doing it from the awakeFromNib method.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.