I found the question Creating NSMenu with NSMenuItems in it, programmatically? but failed to get the solution to work in my application. I tried combining the code from the question and accepted answer to get the following:
NSMenu *fileMenu = [[NSMenu alloc] initWithTitle:@"File"];
NSMenuItem *newMenu = [[NSMenuItem alloc] initWithTitle:@"New" action:NULL keyEquivalent:@""];
NSMenuItem *openMenu = [[NSMenuItem alloc] initWithTitle:@"Open" action:NULL keyEquivalent:@""];
NSMenuItem *saveMenu = [[NSMenuItem alloc] initWithTitle:@"Save" action:NULL keyEquivalent:@""];
[fileMenu addItem: newMenu];
[fileMenu addItem: openMenu];
[fileMenu addItem: saveMenu];
NSMenuItem *fileMenuItem = [[NSMenuItem alloc] init];
[fileMenuItem setSubmenu: fileMenu];
[[NSApp mainMenu] addItem: fileMenuItem];
[fileMenuItem release];
No File
menu is created. Placement of the above code before or after the other code in the main function is inconsequential. I also tried placing in applicationDidFinishLauching
to no avail. Why does the above code fail to function, and how can I give my application a menu without using any XIB or Storyboard files?