Conditionally Enable/Disable Catalyst Menubar Items

Viewed 284

I'd like to conditionally enable/disable items in the menubar on Catalyst based on a value in a View Controller across multiple windows.

I can use the validate(_:) method to enable/disable the menubar item based on the command but need a way to do it based on the on-screen View Controller.

Any ideas?

1 Answers

This docs page explains how you can adjust the menu commands from view controllers, and there is also a great sample project, so make sure to check it.

Quoting from the page:

This sample creates its Edit menu content based on the first responder in the responder chain. You can adjust menu commands by using canPerformAction:withSender:. The master view controller overrides this function to enable menu commands based on the table view state or the state of the pasteboard.

Related