Question

Is there any way to get an NSPopover to appear when a user clicks on the NSStatusitem in the status bar?

so far in my header i have this:

IBOutlet NSStatusItem *statusitem;

and this :

@property (assign) IBOutlet NSPopover *pop;

Under the method, i have this:

[[NSImage imageNamed:@"mic.png"]setSize:NSMakeSize(20,20)];
statusitem = [[NSStatusBar systemStatusBar]statusItemWithLength:NSVariableStatusItemLength];
[statusitem setHighlightMode:YES];
[statusitem setImage:[NSImage imageNamed:@"mic.png"]];
[statusitem setMenu:menu];
[statusitem setAction:@selector(pop:)]

and

- (void)pop:(id)sender{
[[self pop]showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxXEdge];
}

Is there anyway to get this to work?

Was it helpful?

Solution

That's pretty close to being correct. Your statusItem property should be retain, and not an IBOutlet, since you are creating it in code. Also, you can't have both a menu and an action for your status item -- if you have a menu, it will be opened when you click on the status item, rather than firing your action method. So, if you make those changes,and you have your popover setup in IB, this should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top