• 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
programmatically modifying NSPopUpButton's NSMenu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

programmatically modifying NSPopUpButton's NSMenu


  • Subject: programmatically modifying NSPopUpButton's NSMenu
  • From: Chuck Soper <email@hidden>
  • Date: Sat, 20 Dec 2003 10:23:19 -0800

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.
  • Follow-Ups:
    • Re: programmatically modifying NSPopUpButton's NSMenu
      • From: p3consulting <email@hidden>
  • Prev by Date: Re: Shell script build phases
  • Next by Date: Re: Newbie - Buy book(s) or read free documentation, which is best ????
  • Previous by thread: Re: Shell script build phases
  • Next by thread: Re: programmatically modifying NSPopUpButton's NSMenu
  • Index(es):
    • Date
    • Thread