Re: programmatically modifying NSPopUpButton's NSMenu
Re: programmatically modifying NSPopUpButton's NSMenu
- Subject: Re: programmatically modifying NSPopUpButton's NSMenu
- From: Chuck Soper <email@hidden>
- Date: Sat, 20 Dec 2003 11:53:54 -0800
Thanks for your response. It turns out that
myPopUpButton was nil. After further
investigation I discovered that my outlet in the
nib had a slightly different name than the outlet
I was referring to in my source files. So,
nothing was connected even though it looked
connected. Now everything works fine! And I send
all messages to the NSPopUpButton instance not
the NSMenu.
- I was expecting not having an outlet in my
source when it exists in the nib to be a compile
time error.
- I was also kind of expecting [myPopUpButton
numberOfItems] when myPopUpButton is nil to be a
run time error.
Chuck
At 8:22 PM +0100 12/20/03, p3consulting wrote:
All the methods you are invoking are correct (numberOfItems etc.),
BUT you have to use them on the the poup button itself !
e.g. [myPopUpButton numberOfItems] [myPopUpButton removeItemAtIndex:0] etc.
see the NSPopUpButton documentation.
if they still don't work you should first check
that myPopUpButton is not nil in awakeFromNib.
myPopUpButton being nil in awakefromNib could be
the consequence of not loading the nib the
correct way,
often by double instantiation of the window
controller
(manually calling alloc/init on the
window controller class...)
Pascal Pochet
P3 Consulting
On 20 dic. 2003, at 19:23, Chuck Soper wrote:
Hello,
How do I programmatically add and remove menu
items from an NSPopUpButton at runtime? I've
done numerous searches on cocoa.mamasam, but I
wasn't able to find the answer. I did find one
post that said, "This problem has been
discussed to death, so please see the archives."
In IB, I dragged an NSPopUpButton to my window.
This window is in a separate nib file. I added
an NSPopUpButton outlet to my controller and
made the connection. I added an action to my
controller for selecting the popup menu and
implemented the method.
In awakeFromNib, numberOfItems is always zero yet the menu has two items:
int numberOfItems = [[myPopUpButton menu] numberOfItems];
printf("menu Items = %d\n", numberOfItems);
numberOfItems = [myPopUpButton numberOfItems];
printf("popup Items = %d\n", numberOfItems);
In awakeFromNib, the following code does nothing:
[myPopUpButton removeAllItems];
Or:
[[myPopUpButton menu] removeItemAtIndex:0];
[[myPopUpButton menu] removeItemAtIndex:1];
At runtime, my popup menu has two items and I
have confirmed that my action for selecting the
popup menu is being called. I'm sure I'm
missing something simply. Can someone help me?
Thanks, Chuck
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.