Question

I have a weird "bug". I'm creating an "Edit" menu for my Mac OSX application. It shall contain copy, paste, select all et.c. I have solved the functionality by simply connecting the appropriate selectors in the first responer to the menues.

I connect my paste menuitem to paste: I connect my copy menuutem to copy:

This work great, and I am able to copy and paste using both the menu and shortcuts associated with them.

However, when connecting to the copy: selector of the first responer, two new menu options appear at the bottom: "Dictations" and "Special Character".

How do I remove them? I am creating the menus in Interface Builder in a xib-file.

Was it helpful?

Solution

Solved it by manually removing the submenus from code:

- (void)windowDidLoad {
    [super windowDidLoad];
    [self presentModalViewController:self.bookshelfController withData:nil];

    [self removeLastMenuItemsOfRedigeraMenu];
}

-(void)removeLastMenuItemsOfRedigeraMenu
{

    NSMenu *mainMenu = [NSApp mainMenu];
    for (NSMenuItem* subMenu in mainMenu.itemArray)
    {
        if ([subMenu.title isEqualToString:@"Redigera"])
        {
            NSArray *array = subMenu.submenu.itemArray;
            for (int i = (int)array.count-1; i >= 0; i--)
            {
                if (i >= 11)
                {
                    [subMenu.submenu removeItem:[array objectAtIndex:i]];
                }
            }
        }
    }
}

Please post if you have a better answer

OTHER TIPS

You can change the name of the menu item to any other, and through the awakeFromNib back with the name you want.

Something like:

    [_editMenuItem.submenu setTitle:NSLocalizedString(@"Edit",NULL)];

It only adds these menus when the title is "edit" on any of the supported languages​​. But just when loading the interface, then (awakeFromNib) can already put the name again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top