Search code examples
cocoadynamicnsmenuitemnsmenu

Rebuild NSMenuItems in StatusBar


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.


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)