• 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: Gregory Weston <email@hidden>
  • Date: Thu, 08 Mar 2012 06:45:57 -0500

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?

My first suggestion would be that it's very weird and potentially troublesome to have static items in a menu that come after a dynamic list of arbitrary size. Even if you can guarantee the user is never going to have to scroll through 183 items to get to the Refresh command, you're still working against the development of any kind of "muscle memory." If I were doing something like this design, my menu have the refresh command first, then the count, the separator and then the dynamic list. I don't think a quit command belongs in such a menu at all, but if you really need it I'd still put it above the dynamic list. Then your solution becomes just deleting everything after a given index.

That said: Your current solution should work in the abstract. You don't describe the "mess" you're causing but I'm quite confident it's a logic error rather than any kind of fundamental problem with using removeItemAtIndex: for this task. Other alternatives that might work well involve finding items to remove based on their tag, target or represented object, any one of which you may already be setting depending on how you react to those items being invoked.
_______________________________________________

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


  • Prev by Date: Re: Accessing array in thread safe way
  • Next by Date: Re: Finding object array index when iterating through array
  • Previous by thread: Re: Problem with refreshing NSMenuItems
  • Next by thread: Sandbox, CoreData, Spotlight
  • Index(es):
    • Date
    • Thread