NSPopUpButton and addItemWithTitle

Discussion in 'Mac Programming' started by hiddenpremise, Jan 26, 2009.

  1. macrumors regular

    hiddenpremise

    Joined:
    Jul 25, 2008
    Location:
    Somewhere between my imagination and reality
    #1
    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 :)
     
  2. macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #2
    This might be stating the obvious, but you can also add a menuitem in interface builder.
     
  3. thread starter macrumors regular

    hiddenpremise

    Joined:
    Jul 25, 2008
    Location:
    Somewhere between my imagination and reality
    #3
    This is true, but for the sake of the exercise, I want to figure out how to do it programmaticly.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. macrumors 6502

    Joined:
    Jul 25, 2006
    #5
    -init methods are generally the wrong place to interact with GUI objects. You need to wait until at least -awakeWithNib.
     

Share This Page