Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 603009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:53:05+00:00 2026-05-13T16:53:05+00:00

I have some submenu inserted as Window item submenu of Main Menu I have

  • 0
  1. I have some submenu inserted as Window item submenu of Main Menu
  2. I have an instance of my object (let’s assume its class name is MenuController) inherited from NSObject and supports 2 from NSMenuDelegate methods:
    – numberOfItemsInMenu:
    – menu:updateItem:atIndex:shouldCancel:
  3. This instance added as Blue-Object into NIB for awaking at runtime
  4. Object from steps 2-3 configured as delegate for submenu (step 1)

Now, I can provide submenu content in runtime.

Next, I do following: I can add new items or remove old from an array (inside MenuController which contains menu titles) that mapped to real submenu via protocol and delegate.
All works just fine.
Except one thing: I like assign shortcuts to my dynamic menu items.
CMD-1, CMD-2, CMD-3, etc

Window / MySubmenu / MyItem1 CMD-1, MyItem2 CMD-2, …

So, for call some items I don’t wanna go to Window / MySubmenu / MyItem to click it by mouse, I wanna press just one shortcut, like CMD-3 to call the item.

Ok, periodically it works as expected. But, generally, I have no way to inform Main Menu about my nested submenu changes, except open the Window / MySubmenu to reload its content.
One stable way to reproduce the issue – just try to remove some item and press its old shortcut assigned to it, after you create new item as replace for deleted – bingo – shortcut wont work before you navigate to Window / MySubmenu to see current submenu content.

I don’t know a way to force main menu to rebuild its submenus…
I tried: [[NSApp mainMenu] update] and games with NSNotificationCenter for send NSMenuDidAddItemNotification, NSMenuDidRemoveItemNotification, NSMenuDidChangeItemNotification

I tried outlet to my submenu and call to update method explicitly – there is no way…
Some times AppKit calls my delegate methods – and I see that, sometimes it doesn’t want to call anything. Looks like a random strategy.

How can I make sure that after “some call” my submenu will be in actual state after internal array modifications?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:53:05+00:00Added an answer on May 13, 2026 at 4:53 pm

    To implement 1:1 mapping, implement in delegate these 3 methods:

    - (BOOL)menu:(NSMenu *)menu
    updateItem:(NSMenuItem *)item 
    atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel
    

    and

    - (NSInteger)numberOfItemsInMenu:(NSMenu *)menu
    

    and

    - (void)menuNeedsUpdate:(NSMenu *)menu
    {
        if (!attachedMenu)
            attachedMenu = menu;
        if (!menu)
            menu = attachedMenu;
        NSInteger count = [self numberOfItemsInMenu:menu];
        while ([menu numberOfItems] < count)
            [menu insertItem:[[NSMenuItem new] autorelease] atIndex:0];
        while ([menu numberOfItems] > count)
            [menu removeItemAtIndex:0];
        for (NSInteger index = 0; index < count; index++)
            [self menu:menu updateItem:[menu itemAtIndex:index] atIndex:index shouldCancel:NO];
    }
    

    attachedMenu – is internal var of type NSMenu*

    Next, when you wanna force refresh the submenu, anytime – just call

    [self menuNeedsUpdate:nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made some menu with a slide down submenu. It should work fine
I have this HTML: <div class=info> Some Text Boom A <a onclick=menu('id1');>Link</a> | More
I have some very simple XML: <properties> <property> <name>BobFish</name> <explaination>Bob is a fish.</explaination> </property>
I have a css horizontal menu with a menu / submenu display working on
I have a UINavigationController with 3 levels of hierarchy: Menu->Submenu->Details. Menu and Submenu are
I have some ContextMenu With some menuItems. One of the menuItems is Add Item....
I'm using jQuery to create a simple, but large dropdown menu. I have some
The main idea is to have a color-specific menu throughout the whole site. In
I have a problem with js menu code. first let me explain what I
I have some files that are uuencoded, and I need to decode them, using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.