Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Menu Item

One of my e-books explains how to add a new menu item. Well, that's not very difficult to figure out. It's not difficult to figure out how to link an IBAction to a new menu item, either. But this book and Google search results don't explain how to disable a menu item. More particularly, I want to disable Preferences and Quit, depending on where window currently appears. If the application currently shows the Preferences window, I want to disable these menu items.

enter image description here

Suppose that I have an IBOutlet named preferencesMenu and then that I have

[preferencesMenu setEnabled:NO];

, that won't disable the menu item in question. So how do you disable a particular menu item?

Thank you for your advice.

Tom

like image 355
El Tomato Avatar asked Jan 18 '13 00:01

El Tomato


2 Answers

NSMenuItems disable themselves automatically only if both their target and selector are nil and NULL respectively.

[preferencesMenu setTarget:nil];
[preferencesMenu setAction:NULL];

Which a quick test reveals leads to this:

enter image description here

like image 167
CodaFi Avatar answered Nov 14 '22 23:11

CodaFi


Just set the target to nil. I'll do the job.

[preferencesMenu setTarget:nil];
like image 31
Matthieu Riegler Avatar answered Nov 14 '22 23:11

Matthieu Riegler