We Recommend

Programming in Objective-C Programming in Objective-C
Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming. The book makes no assumption about prior experience with object-oriented programming languages or with the C language (upon which Objective-C is based). And because of this, both novice and experienced programmers alike can use this book to quickly and effectively learn the fundamentals of Objective-C.


Posted By

0xced on 09/18/07


Tagged

menu item nsmenu nsmenuitem


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

tcol


Add a menu item


Published in: Objective C 


Programmatically add a menu item


  1. // Beware: the keyEquivalent must be lowercase in order not to have the shift modifier
  2. NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Action" action:@selector(menuItemAction:) keyEquivalent:@"r"];
  3. [menuItem setTarget:self];
  4. [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
  5. // Add the menu item at the end of menu whose index is 1 (most probably the File menu)
  6. [[[[NSApp mainMenu] itemAtIndex:1] submenu] addItem:menuItem];

Report this snippet 

You need to login to post a comment.