I'm trying to create an NSMenu in my application. I succesfully create the menu, with some fixed items, and now I have to add some items programmatically. I succeed also in that, but it adds the item at the bottom of the others. There's a way to put this programmatically created items between fixed items? Here's my code:
.h:
@interface AppController : NSObject {
IBOutlet NSMenu *statusMenu;
NSStatusItem *statusItem;
}
.m
[statusMenu setAutoenablesItems:NO];
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setMenu:statusMenu];
NSImage *statusImage = [[NSImage alloc] initWithContentsOfFile:@"Icon.icns"];
[statusItem setImage:statusImage];
[statusItem setTitle:@"Multibox"];
[statusItem setHighlightMode:YES];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Carlo | 0000000000"
action:@selector(fooClicked:) keyEquivalent:@""];
[item setTarget:self];
[statusMenu addItem:item];
You want to use the insertItem:atIndex:
family of methods rather than the addItem:
ones.