Cannot seem to setEnabled:NO on NSMenuItem

后端 未结 8 1626
故里飘歌
故里飘歌 2021-02-12 10:51

I have subclassed NSMenu and connected a bunch of NSMenuItem\'s via Interface Builder. I have tested via the debugger to see that they really get initi

8条回答
  •  没有蜡笔的小新
    2021-02-12 11:15

    You can solve this problem without subclassing.

    If only you need is standard menu + some custom NSMenuItems that can be disabled on your control, than you can just:

    1. Add one more menu node - just drag and drop Submenu Menu Item from Object library to your menu.

    2. Add all NSMenuItems you want to manage to this new Menu node.

    3. Open Attributes inspector for your New Menu node, and switch off Auto Enables Items option:

    4. configure any other options of your menu & items.

    Now you can write a code like:

    @property (weak) IBOutlet NSMenuItem *hidePlateMenuItem;
    ...
    [self.hidePlateMenuItem setEnabled:NO];
    

    and it will works well.

提交回复
热议问题