问题
I would like to create a status bar application which has non-menu style. same as FaceTab for facebook (I mean only interface, not functional)... this is my codes:
-(void)awakeFromNib{
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setView:customView];
//[statusItem setMenu:menu];
[statusItem setTitle:@"Status"];
[statusItem setHighlightMode:YES];
}
..... so once I Use NSMenu everything works fine but when I use NSView and CustomView outlet nothing appear on menu bar. Help plz!
回答1:
There are several moving parts involved, so the best advice I can give is to check out this excellent example project from Vadim Shpakovski.
回答2:
At the end of your awakeFromNib method, you may need to call retain on the statusItem so that it doesn't go out of scope. I was struggling with this same problem, and adding [statusItem retain];
fixed it so that I now see my Status menu in the Mac OS status bar.
-(void)awakeFromNib{
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setView:customView];
// in my code, this is uncommented, and menu is an instance variable.
//[statusItem setMenu:menu];
[statusItem setTitle:@"Status"];
[statusItem setHighlightMode:YES];
// this was needed to get the icon to display in the status bar.
[statusItem retain];
}
来源:https://stackoverflow.com/questions/7770539/add-customview-to-nsstatusitem