Question

I'm trying to have a dynamic number of NSMenuItems in a Statusbar app. Right now I'm reading in a list in the awakeFromNib. But this only happens once.
What do I have to do to rebuild my NSMenuItems while the applicaiton is running?
Should it happen in something like -(void)menuNeedsUpdate:(NSMenu *)menu?
Can somebody give me a push in the right direction please.

Was it helpful?

Solution

Try setting the NSMenuDelegate on your header file (the .h file), like this:

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate,NSMenuDelegate>{
}

(or in the header file of the class that you need the selector to be called)

OTHER TIPS

Use – addItem: – removeItem: methods.

NSMenuItem *test = [[NSMenuItem alloc] initWithTitle:@"test" action:@selector(test) keyEquivalent:@"a"];
[[StatusItem menu]  addItem:test];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top