• 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: Novice Question: Getting Menu selections
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Novice Question: Getting Menu selections


  • Subject: Re: Novice Question: Getting Menu selections
  • From: Dave Hersey <email@hidden>
  • Date: Fri, 14 Sep 2007 02:06:37 -0400
  • Thread-topic: Novice Question: Getting Menu selections

Hi Chris,

Two quick things I see that may help:

> void  InsertItemIntoMenu(...)
> {
...
> [theItem setAction:@selector(testItemSelected:)];
...
> }

testItemSelected: should be menuItemSelected: since that's the name of your
method.

And this,

> UnitTest[1908] *** +[NSWindow orderedWindows]: selector not recognized

Indicates that you're using the orderedWindows selector incorrectly. It
appears that you're calling [NSWindow orderedWindows] somewhere, rather than
[NSApp orderedWindows].

The declaration for that one is in NSApplication:
- (NSArray *) orderedWindows;

...so, you'd use an instance of NSApplication with that, presumably NSApp.

Try fixing those things and see if the behavior improves.

- Dave


On 9/14/07 1:20 AM, "Christopher Kempke" <email@hidden>
wrote:

> I'm a Cocoa novice, converting my aging Carbon application framework
> to Cocoa.  I'm building my interfaces directly, not using IB (the
> framework has it's own builder tools), and using Objective C++.
>
> In Carbon, my menu items had a command code associated with them,
> which I'd snag when the Carbon Event fired and send off for
> handling.  I'm trying to duplicate that functionality here.
>
> So, I've created a Menu Controller object:
>
> #if (UT_TARGET_COCOA)
> @interface MenuController : NSObject
> -(id)init;
> -(void)menuItemSelected:(id)sender;
> @end
> #endif
>
> And it's implementation:
> @implementation MenuController
> -(id)init
> {
> return [super init];
> }
> -(void)menuItemSelected:(id)sender
> {
> CroPL::CPFGetApplication()->HandleCommand([sender tag]);
> }
> @end
>
> I create a static instance of it:
>
> static MenuController* sMenuController = [[MenuController alloc] init];
>
> And when I create the menus, I set the tag to the "command code" from
> my old architecture, the target to the static menu controller, and
> the action to the MenuItemSelected: message:
>
> void InsertItemIntoMenu(platformMenu menu, const UtString& text,
> sInt16 before)
> {
> CFStringRef inText = text.ToCFStringRef();
> NSMenuItem* theItem = [menu insertItemWithTitle: (NSString*)inText
> action: nil keyEquivalent: @"" atIndex: before];
> [theItem setTarget:sMenuController];
> [theItem setAction:@selector(testItemSelected:)];
> CFRelease(inText);
> }
>
> PlatformMenu here is NSMenu*, and UTString is private string class
> that knows how to convert to CFStringRef (bridged to NSString*).
>
> This doesn't work.  A breakpoint on the menuItemSelected: method
> never fires, and the debugger console tells me only:
> 2007-09-13 22:05:19.269 UnitTest[1908] *** +[NSWindow
> orderedWindows]: selector not recognized
> I've verified that neither the static MenuController nor the created
> item are nil as of when I insert.
>
> I've been poking at this for days without luck.   I'm probably
> completely missing some important step.  Can anyone take pity on me?
>
> --Chris



_______________________________________________

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

References: 
 >Novice Question: Getting Menu selections (From: Christopher Kempke <email@hidden>)

  • Prev by Date: Novice Question: Getting Menu selections
  • Next by Date: Re: resetting ivars safely
  • Previous by thread: Novice Question: Getting Menu selections
  • Next by thread: NSWindow contentView buffer
  • Index(es):
    • Date
    • Thread