• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: programmatically modifying NSPopUpButton's NSMenu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programmatically modifying NSPopUpButton's NSMenu


  • Subject: Re: programmatically modifying NSPopUpButton's NSMenu
  • From: p3consulting <email@hidden>
  • Date: Sat, 20 Dec 2003 20:22:57 +0100

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.

  • Follow-Ups:
    • Re: programmatically modifying NSPopUpButton's NSMenu
      • From: Chuck Soper <email@hidden>
References: 
 >programmatically modifying NSPopUpButton's NSMenu (From: Chuck Soper <email@hidden>)

  • Prev by Date: Re: docs for binding options in IB
  • Next by Date: Re: docs for binding options in IB
  • Previous by thread: programmatically modifying NSPopUpButton's NSMenu
  • Next by thread: Re: programmatically modifying NSPopUpButton's NSMenu
  • Index(es):
    • Date
    • Thread