PDA

View Full Version : NSPopUpButton and addItemWithTitle




hiddenpremise
Jan 26, 2009, 01:41 PM
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

- (id) init {
if (self = [super init])
{
[mtype addItemWithTitle: @"Test Item"];
}
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
Jan 26, 2009, 02:03 PM
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

- (id) init {
if (self = [super init])
{
[mtype addItemWithTitle: @"Test Item"];
}
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.

hiddenpremise
Jan 26, 2009, 02:10 PM
This might be stating the obvious, but you can also add a menuitem in interface builder.

This is true, but for the sake of the exercise, I want to figure out how to do it programmaticly.

kainjow
Jan 26, 2009, 02:24 PM
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
Jan 26, 2009, 03:11 PM
-init methods are generally the wrong place to interact with GUI objects. You need to wait until at least -awakeWithNib.