> Date: Wed, 25 Sep 2002 02:01:31 -0400 (EDT)
> From: Michael Chang <email@hidden>
> To: email@hidden
> Subject: Populating an NSPopUpButton at startup...
>
> Hi, folks.
>
> Here's the situation: As the title states, I'm trying to populate an
> NSPopUpButton when the application starts up so that the user actually has
> something to select. The NSPopupButton _is_ connected to an outlet in one
> of my classes; however, the outlet is an instance variable, not a class
> variable, so I can't just call a class method which uses the
> outlet, since the class hasn't been instantiated yet. Keep in mind that
> I'm pretty new to Cocoa programming --- there may be an obvious solution
> that I'm not seeing.
> I'm pretty sure that the only way to do it is within main(), just before
> the main event loop begins. Please correct me if I'm wrong.
Hi Michael,
From the above I'm not sure what you're looking for, but I'll share some of
my knowledge of NSPopUpButton, hoping that it will help you.
I'll assume you're making a nib based product, which is _strongly_
recommended for any programs using AppKit classes.
NSPopUpButton is a button which contains a number of NSMenuItems. When you
select a different item, _two_ action events are fired: one from the
menuItem you select, and one from the popUpButton. The standard way to
connect these events to receiving objects is to connect the popUpButton (or
menuItems) in Interface Builder (IB) to an IBAction method in some receiving
class instance. I find that the easiest way is to just connect the
popUpButton, and determine at run time which menuItem is selected.
If you know in advance which menuItems you want to be available to the user,
you can add them in IB. If you want to create them dynamically, you need to
create an IBOutlet in your controler object that you connect (in IB) to the
popUpButton. Then, in the conctroler's 'awakeFromNib' method you can add the
menuItems you want to this outlet. The awakeFromNib method is called
automatically after all objects in the nib are instantiated and all outlets
are connected. Your controler must of course be in the same Nib file as the
NSPopUpButton instance, for this to work.
I hope this helps,
Patrick
_______________________________________________
studentdev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/studentdev
Do not post admin requests to the list. They will be ignored.