I am trying to change the titles of some of the items in my Cocoa app's main menu. I have tried setting them both within IB and also programmatically from my app's applicationDidFinishLaunchingWithOptions: method. Either way, the title property of my NSMenuItem object does change. But none of my changes are reflected in the actual title of the item at the top of the screen when the app is running.
Can anyone explain what is going on? And how can I change this?
EDIT: The data structure is the default one that IB sets up:
NSApplication *app = [NSApplication sharedApplication];
NSMenu *mainMenu = [app mainMenu];
NSArray *itemArray = [mainMenu itemArray];
NSMenuItem *firstItem = [itemArray objectAtIndex: 0];
NSMenu *submenu = [firstItem submenu];
I have changed the title properties of both firstItem and subMenu to be my desired title. Yet the default one still shows.
Sometimes, this just does not work, because Cocoa doesn't like your title :-p That happens e.g. when the title you chose is the localized app name, but it wants to display the non-localized app name. A little trick can help...
Yeah, it's crazy, but that extra character at the end made all the difference. (You may also append just a SPACE, but then the menu item grows, which is probably not what you want.)
Tested on OS X 10.9.5.
Another thing:
You have to do all of this AFTER you have showed a window. Otherwise it just does not work. Furthermore if you do this procedure at app start, and then later when the window is shown do it again, it may not work too.