Pergunta

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.

Foi útil?

Solução

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)

Outras dicas

Use – addItem: – removeItem: methods.

NSMenuItem *test = [[NSMenuItem alloc] initWithTitle:@"test" action:@selector(test) keyEquivalent:@"a"];
[[StatusItem menu]  addItem:test];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top