4

On OS X app, what is the technique to show a NSPopover when the mouse is over a NSMenuItem (like in spotlight for example).

Thanks a lot!!! Christopjhe

MByD
  • 135,866
  • 28
  • 264
  • 277

2 Answers2

4

I know it's been a while, but if you still haven't found a solution:

Register your class as a NSMenuDelegate to the menu that contains the NSMenuItem, and implement

- (void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item;

then show the popover when this method is called.

MByD
  • 135,866
  • 28
  • 264
  • 277
  • 3
    and how do I point the popover to the menu item if NSMenuItem has no bounds and no view? I am new to OSX development. If you can show some code I appreciate. Thanks. – Duck Apr 22 '14 at 20:30
-1

Can you show your code in the question? It would make it easier to help you. But without knowing what your code looks like, this might work for you:

Add this to your statusItem

self.statusItem.action = @selector(clickStatusBar:);

Add method similar to this to make the popover appear

- (void)clickStatusBar:(id)sender {
    [[self popover] showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
}
wigging
  • 8,492
  • 12
  • 75
  • 117
  • I do not have any code to show since I do not know how to do code that ;) But thanks for the answer, I will try this and if ti works I will update for some mouse over instead of click. – Christophe HAMERLING Feb 20 '12 at 17:23
  • @ChristopheHAMERLING Here are two tutorial videos that can help you get started: Create A MenuBar Application - http://youtu.be/HRPMFNDcfLY Create an NSPopover - http://youtu.be/P3uehLU67cg – wigging Feb 20 '12 at 19:38
  • this will not work because sender will be a NSMenuItem and NSMenuItems have no bounds. This will crash. – Duck Apr 22 '14 at 20:31
  • @Gavin - excuse my ignorance but I am extremely new to development on OSX (~2 weeks and struggling) but you say "add this to your statusitem"... what is that? where do I add this? At this time all I have is a menu on interface builder linked to an action on a class. Thanks. – Duck Apr 24 '14 at 04:11