Sometimes in multiple user scenario having different authorizations ,in the app we may need to provide users with different menu item depending on their permission set in the app. Suppose we need to add a sub menu item having title ‘title’ under File Menu of the application. Then following code can be implemented.
NSMenuItem* newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"title" action:@selector(functionToBeCalledOnClick:) keyEquivalent:EMPTY_STRING]; [newItem setEnabled:YES]; NSMenu* rootMenu = [NSApp mainMenu]; NSMenuItem* menu = [rootMenu itemWithTitle:@"File"]; [[menu submenu] insertItem:newItem atIndex: [[[menu submenu] itemArray] count]]; [newItem release];