• 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: Newbie NSPopUpButton addItemWithTitle: problem from a menu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie NSPopUpButton addItemWithTitle: problem from a menu


  • Subject: Re: Newbie NSPopUpButton addItemWithTitle: problem from a menu
  • From: Carlos Weber <email@hidden>
  • Date: Sat, 25 May 2002 10:03:37 -1000

On Friday, May 24, 2002, at 05:11 , Hunt Sparra wrote:

I have created a document based application with a
NSPopUpButton. I load the button values by using [popUpButon
addItemWithTitle:@some title]. This works fine when called from
the windowDidLoadNib and when using a button in the
MyDocument.Nib. I cannot seem to get it to work when call the
method from the MainMenu.Nib. I dragged my MyDocument.h to
the Nib, instantiated MyDocument.h, and then wired up a menu
item with the action in MyDocument.

If I understand aright, you are trying to wire an action which belongs to your document (adding items to a popup) to a menu item (the menu itself, of course, residing in MainMenu.nib). If that's what you're wanting to do, you are going about it wrong (tho this is one of those "obvious" things that is ONLY obvious in retrospect, once you grok it).

What you've done: by dragging your MyDocument.h header onto the MainMenu.nib window and instantiating it, you have created a unique instance of your MyDocument class, which is unarchived, along with your menu, whenever your program is launched. THIS PARTICULAR INSTANCE, and no other, is wired to your menu item. This doesn't do you any good, though, because the windows you see on your screen are associated with other instances of your MyDocument class which are created in the "normal" way for a document-based Cocoa app.

What you want to do: use the First Responder mechanism, embodied in the big "1" icon sitting in the main window of your MainMenu.nib. You'll have to read NSResponder documentation to understand the responder chain, but what you need to do is like this: say in your MyDocument class you have an instance method which adds an item to your popup, or whatever it does. Call it -populateMyPopup:. You can add an action with this name to the First Responder in MainMenu.nib using IB, just as you would add an action to any other class you would create in IB. Assign that action method as the target of your menu item. That's all. It will "just work". (As I said, to understand why you have to read up on the responder chain).

Hope it helps.
_______________________________________________
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.

References: 
 >Newbie NSPopUpButton addItemWithTitle: problem from a menu (From: "Hunt Sparra" <email@hidden>)

  • Prev by Date: Re: In Praise of the new O'Reilly Cocoa book
  • Next by Date: Detecting whether app at path is running?
  • Previous by thread: Newbie NSPopUpButton addItemWithTitle: problem from a menu
  • Next by thread: Why can't I introduce new variables after init stage?
  • Index(es):
    • Date
    • Thread