Reputation: 81
I currently have an NSStatusItem
for the status bar that is initialized in awakeFromNib
like this:
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setMenu:statusMenu];
[statusItem setImage:statusImage];
[statusItem setAlternateImage:statusHighlightedImage];
[statusItem setHighlightMode:YES];
[statusItem setTarget:self];
I have an NSMenu
that opens when the icon is clicked. One of the options, when clicked, is supposed to open an NSPopover
from the status bar icon. To do that, I have this code, which is connected to the menu item via Interface Builder:
- (IBAction)prefs:(id)sender {
NSRectEdge prefEdge = NSMaxYEdge;
[[self pop] showRelativeToRect:[[statusItem view] bounds]
ofView:[statusItem view]
preferredEdge:prefEdge];
}
However, when I click the menu item that should open the Popover, nothing happens. Is there any particular reason why this might be the case? As far as I can tell, it should be possible to do.
Thanks in advance. I looked through Stack Overflow the best I could, but if there's a true duplicate question, please link me to it.
FYI: The statusItem
variable is the NSStatusItem
.
Upvotes: 4
Views: 1814
Reputation: 2194
I don't know if this problem was resolved already, but I have few notes.
prefs:
IBAction
is being called.[(NSMenuItem *)sender view]
as your anchor and its bounds.Upvotes: 0
Reputation: 28242
You need to set a view yourself using [statusItem setView:]
for [statusItem view]
to return non-nil
.
If you don't mind using private API, you could try calling [statusItem _button]
, instead, though this won't be allowed if you plan on submitting to the App Store.
Upvotes: 2