• 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: Select MenuItem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Select MenuItem


  • Subject: Re: Select MenuItem
  • From: Lorenzo <email@hidden>
  • Date: Sat, 05 Jan 2008 03:21:52 +0100

Thanks Peter, I succeded with this code:

    NSPopUpButtonCell *btnCell = [[NSPopUpButtonCell alloc] init];
    [btnCell setMenu:myContextMenu];
    [btnCell performClickWithFrame:[sender frame]
             inView:[sender superview]];

    [btnCell release];
    [myContextMenu release];


Best Regards
--
Lorenzo
email: email@hidden

> From: Peter Ammon <email@hidden>
> Date: Fri, 04 Jan 2008 18:07:27 -0800
> To: Lorenzo <email@hidden>
> Cc: email@hidden
> Subject: Re: Select MenuItem
>
>
> On Jan 4, 2008, at 6:01 PM, Lorenzo wrote:
>
>> Hi,
>> I click on a button and build my own NSMenu then I popup the menu with
>>
>>     [NSMenu popUpContextMenu:
>>
>> It works well. Now I would pre-select a MenuItem so when I click on
>> the
>> button the menu pops-up putting the MenuItem under the mouse.
>> How can I do that?
>
> You should not use a contextual menu to simulate a popup menu.  If
> you want to programmatically trigger a popup menu, create an
> NSPopUpButtonCell, assign it the menu and initial item index you
> want, and then call -[NSPopUpButtonCell performClickWithFrame:inView:]
>
> The NSPopUpButtonCell can be transient - it's fine to create it right
> when you receive the click and destroy it afterwards.
>
> -Peter
>

_______________________________________________

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: 
 >Re: Select MenuItem (From: Peter Ammon <email@hidden>)

  • Prev by Date: Re: Editable NSTextField and layout
  • Next by Date: Re: Editable NSTextField and layout
  • Previous by thread: Re: Select MenuItem
  • Next by thread: NSAppleEventDescriptor & Extracting a Date value
  • Index(es):
    • Date
    • Thread