How to set the first entry in NSPopUpButton

Discussion in 'Mac Programming' started by satyam90, Jan 31, 2008.

  1. macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    Hi, I am using Cocoa with Obj-C
    I am trying to set the first entry under NSPopupButton using [popup selectItemAtIndex:0] in awakeFromNib of the window. I have only one entry in popup button.
    But it is returning run time exception.
    2008-01-31 19:52:55.493 Appln 3[13912] *** Assertion failure in -[NSMenu itemAtIndex:], Menus.subproj/NSMenu.m:713
    2008-01-31 19:52:55.493 Appln 3[13912] Exception raised during posting of notification. Ignored. exception: Invalid parameter not satisfying: (index >= 0) && (index < (_itemArray ? CFArrayGetCount((CFArrayRef)_itemArray) : 0))

    What might be the cause?
     
  2. macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #2
    Try putting the code in windowControllerDidLoadNib.
     
  3. thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #3
    I found that windowControllerDidLoadNib is in NSDocument class. I don't have any document based object for my GUI. How can I use it in my GUI.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Looks like your popup button doesn't have any items in it. That is why an index of 0 is failing. Check [[popupButton menu] numberOfItems]
     

Share This Page