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.
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
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:
Just set the target to nil. I'll do the job.
[preferencesMenu setTarget:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With