View Full Version : How to set the first entry in NSPopUpButton

Jan 31, 2008, 08:46 AM
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?

Jan 31, 2008, 11:23 AM
Try putting the code in windowControllerDidLoadNib.

Feb 3, 2008, 09:41 PM
Try putting the code in windowControllerDidLoadNib.

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.

Feb 4, 2008, 11:24 AM
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]