0

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.

fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41

2 Answers2

1

Use – addItem: – removeItem: methods.

NSMenuItem *test = [[NSMenuItem alloc] initWithTitle:@"test" action:@selector(test) keyEquivalent:@"a"];
[[StatusItem menu]  addItem:test];
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
1

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)

ozmax
  • 470
  • 6
  • 17
  • I think there where several things wrong. I had to add NSMenuDelegate and I did not reference some outlets. I fixed it by snooping around other peoples code. :) Thanks anyway – fabianmoronzirfas Jul 21 '13 at 11:47