• 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: Re: Which is correct? (itemWithTitle & NSlocalizedString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: Which is correct? (itemWithTitle & NSlocalizedString


  • Subject: Re: Re: Which is correct? (itemWithTitle & NSlocalizedString
  • From: "Michael Ash" <email@hidden>
  • Date: Sun, 3 Sep 2006 15:43:38 -0400

On 9/3/06, Keith Blount <email@hidden> wrote:
Many thanks for your reply, Greg, much appreciated. So
far I have been using NSLocalizedString() in all of my
checks, so it is good to hear that this is necessary,
even if I do have to be careful.

Wherever I can, I use tags and itemWithTag:, but this
isn't possible in some situations; in some situations
I cannot use itemWithTag: or
indexOfItemWithTarget:andAction:, in fact. For
instance, some of my menu items have the same target
and the same action, but different tags which are used
by the action to determine what to do. And
occasionally in these menus there may be other items
with the same tags that determine different actions
(hope that makes sense). In these circumstances, it
seems the only way of determining the item is via the
title...

But the combination of tag+action *is* unique. There is no built-in method to return an item based on that combination, but you can just iterate over the items and look for the right one. If you find yourself doing this frequently, make a category for it.

Also, what about determining an NSMenu rather than a
menu item? I use all of this in -menuNeedsUpdate:, so
to determine the menu that is currently calling this
delegate method I use if ([[menu title]
isEqualToString:NSLocalizedString(@"Some
Menu",nil)])... Given that NSMenus don't allow tags,
is this the only (and best) way to determine the menu?

But every NSMenu (except for the menu bar itself) is actually a submenu of another menu, meaning it's the submenu of an NSMenuItem, and you can just set the tag of that.

Another thing you can do is simply create an outlet to the NSMenu (or
NSMenuItem) and compare pointers. Comparing titles should never be
necessary.

Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Which is correct? (itemWithTitle & NSlocalizedString) (From: Greg Titus <email@hidden>)
 >Re: Which is correct? (itemWithTitle & NSlocalizedString) (From: Keith Blount <email@hidden>)

  • Prev by Date: Re: Subclassing NSTextFieldCell
  • Next by Date: Newbie: Basic problem with NSTableview
  • Previous by thread: Re: Which is correct? (itemWithTitle & NSlocalizedString)
  • Next by thread: Can't get entities from loaded SQL store
  • Index(es):
    • Date
    • Thread