• 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: Using NSToolbar itemForItemIdentifier properly?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSToolbar itemForItemIdentifier properly?


  • Subject: Re: Using NSToolbar itemForItemIdentifier properly?
  • From: j o a r <email@hidden>
  • Date: Sat, 27 Jul 2002 19:46:38 +0200

Clarification
According to the documentation you are supposed to keep track of the toolbars you have in your application and make sure to never supply different toolbar instances with the same instance of a toolbar item. You are also supposed to always return the same toolbar item instance if a given toolbar asks for it again. As far as I know you need to comply with the first requirement, but not the second.

Suggestion
I would suggest that you supply your toolbar items from your window controller (or similar controller object) in which case you probably only have one toolbar (ie. window) per controller.
If this is the case you wouldn't need to think about keeping track of toolbars (since every controller object only has one) and can simply either create a new toolbar item instance every time it is asked for (ie. only comply with the first requirement), or maintain a cached collection of toolbar items for the given toolbar and return one from this collection upon request (ie. comply with both requirements).

Opinion
I think that the reason for the first requirement is that you cannot use the same view object in more than one superview / window at the same time (AppKit limitation), and you cannot simply copy a toolbar item without possibly breaking it's connection to the controller object, thus rendering it useless. I have no idea why they ask you to return the same item if asked for again. First of all the toolbar does not (?) and should not ask the delegate several times for the same toolbar item. Second, if you create a toolbar item subclass which allow for several toolbar item instances in the same toolbar - how would the delegate know if the toolbar is asking for a new item or not? The delegate would need to return a new item for every request, or possibly return the same toolbar item for several positions in the toolbar - probably a bad thing to do.
I think that they should require the delegate to always return a new item, and let the delegate perform whatever maintenance is needed on the willAdd and didRemove delegate messages. Not that it matters that much...


j o a r

On Saturday, Jul 27, 2002, at 16:18 Europe/Stockholm, Pierre-Olivier Latour wrote:

So now what? I am supposed to return a new NSToolbar item each time (that's
what they do in the toolbar example in developer.apple.com/samplecode)
itemForItemIdentifier method is called, or return the same one all the time?
_______________________________________________
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: Using NSToolbar itemForItemIdentifier properly?
      • From: Pierre-Olivier Latour <email@hidden>
References: 
 >Using NSToolbar itemForItemIdentifier properly? (From: Pierre-Olivier Latour <email@hidden>)

  • Prev by Date: Re: determining dragging source
  • Next by Date: Re: Hiding class and method symbols in the compiled program?
  • Previous by thread: Using NSToolbar itemForItemIdentifier properly?
  • Next by thread: Re: Using NSToolbar itemForItemIdentifier properly?
  • Index(es):
    • Date
    • Thread