I try to add an option to my app’s menu with the following code:
NSMenuItem *myNewMenuItem = [[[NSMenu alloc] initWithTitle:@"MenuOption1" action:@selector(myNewMenuItemMethod) keyEquivalent:@"j"] autorelease];
[myMenu addItem:myNewMenuItem];
While compiling I get the title’s warning, which shows up in the console and my app will not run at all. Does anyone knows what I’m doing wrong?
The reason you’re getting a warning is that you’re trying to assign a “
NSMenu” object to something you’ve declared as a “NSMenuItem“.Which is not the same thing. NSMenu objects use NSMenuItems to define the items they display.
Use
[[NSMenuItem alloc] initWIthTitle: action: keyEquivalent:]