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

hiddenpremise

macrumors regular
Original poster
EDIT: Solved
Thanks much everyone :) I just needed to move it out of the init method!


_______
I have a NSPopUpButton in my program.
I have bound that to a variable IBOutlet NSPopUpButton * mtype
I have also bound it to a method - (IBAction) selectMtype;

In the -(id)init method of my controller object I have written
Code:
- (id) init {
if (self = [super init])
{
[INDENT][mtype addItemWithTitle: @"Test Item"];[/INDENT]
}
return (self);

for some reason when I run my program, the item I add does not show up. I'm sure this is a noob error, but I have spent several hours googling and banging my head into a wall to no avail.

Thanks much :)
 

MrFusion

macrumors 6502a
Jun 8, 2005
613
0
West-Europe
I have a NSPopUpButton in my program.
I have bound that to a variable IBOutlet NSPopUpButton * mtype
I have also bound it to a method - (IBAction) selectMtype;

In the -(id)init method of my controller object I have written
Code:
- (id) init {
if (self = [super init])
{
[INDENT][mtype addItemWithTitle: @"Test Item"];[/INDENT]
}
return (self);

for some reason when I run my program, the item I add does not show up. I'm sure this is a noob error, but I have spent several hours googling and banging my head into a wall to no avail.

Thanks much :)

This might be stating the obvious, but you can also add a menuitem in interface builder.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
I'm guessing the problem is you're doing it at init, but the nib loading process isn't finished (or even started) at this point, so your outlet will still be nil. Try changing it to be in the awakeFromNib method instead.
 

kpua

macrumors 6502
Jul 25, 2006
294
0
-init methods are generally the wrong place to interact with GUI objects. You need to wait until at least -awakeWithNib.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.