• 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: Problem with refreshing NSMenuItems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with refreshing NSMenuItems


  • Subject: Re: Problem with refreshing NSMenuItems
  • From: Michael Babin <email@hidden>
  • Date: Thu, 08 Mar 2012 07:02:07 -0600

On Mar 7, 2012, at 2:40 AM, Prime Coderama wrote:

> I have an NSMenu with the following static NSMenuItems
>
> 1. NSMenuItem "Count of people" (hidden)
> 2. NSMenuItem <Separator> (hidden)
> 3. NSMenuItem <Separator>
> 4. NSMenuItem "Refresh List"
> 5. NSMenuItem <Separator>
> 6. NSMenuItem "Quit"
>
> I then dynamically add n-amount of NSMenuItems between (2) and (3). This works great.
>
> The problem I am having, is when I hit "Refresh", I am unsure on how to remove all of the dynamically added NSMenuItems from the NSMenu and add all of the new ones?
>
> I am currently causing a mess using NSMenu:removeItemAtIndex.
>
> Any suggestions?

1. When you add NSMenuItems to the menu, also add them to an array you create and maintain. When your Refresh action occurs, iterate through the array and remove each item from the menu (and clear your array). Then add the new items (to the menu and your array).
2. Set a tag attribute for your dynamic menu items. Then iterate the menu and remove the menu items with that tag attribute.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Problem with refreshing NSMenuItems
      • From: Jerry Krinock <email@hidden>
References: 
 >Problem with refreshing NSMenuItems (From: Prime Coderama <email@hidden>)

  • Prev by Date: Re: Finding object array index when iterating through array
  • Next by Date: Re: Finding object array index when iterating through array
  • Previous by thread: Problem with refreshing NSMenuItems
  • Next by thread: Re: Problem with refreshing NSMenuItems
  • Index(es):
    • Date
    • Thread