NSMenuItem setHidden doesnt work?
-
21-06-2021 - |
Pregunta
I try to hide a NSMenuItem
but the method doesn't work. My NSMenuItem
is not nil (-setTitle
, -setEnabled
work as expected). Outlet is connected correctly in the IB and -setAutoEnableItem
is set to NO.
But [item setHidden:YES];
doesn't change anything. Do you have an idea how to hide a NSMenuItem?
To remove and add the item again is no option for me.
Solución
NSMenuItem
hide problems are due to alternate items. If item have alternate item or items it can't be hidden. But You can solve it like this:
For example You want to hide item2 with alternate items itemAlt2 and itemCtrl2. So make itemAlt2 and itemCtrl2 not alternates and hidden like this:
[itemAlt2 setAlternate: NO];
[itemAlt2 setHidden: YES];
[itemCtrl2 setAlternate: NO];
[itemCtrl2 setHidden: YES];
[item2 setHidden: YES];
And when You need visible item2 just make them alternate and visible like this:
[itemAlt2 setAlternate: YES];
[itemAlt2 setHidden: NO];
[itemCtrl2 setAlternate: YES];
[itemCtrl2 setHidden: NO];
[item2 setHidden: NO];