UIMenuBuilder UIKeyCommand in Modal Sheet on Catalyst

Hi there,

I'm using override func buildMenu(with builder: UIMenuBuilder) to add some menu items (with keyboard shortcuts) to a Catalyst app.

I'm also using override func validate(_ command: UICommand) to enable/disable the menus selectively.

All is working wonderfully except for one situation.

My custom menu items are disabled when presenting a view controller as UIModalPresentationStyle.pageSheet

If I change to present as a fullscreen modal everything works again. The command also work when I build to iPad.

Any idea how to get UIKeyCommands to work when presenting a sheet style modal view controller on macOS?

Thanks in advanced.

I assume you’re building the main menu using your app delegate?

Which objects are responding to the validate() overrides?

A fundamental difference between the fullscreen and page sheet presentations on Catalyst is that page sheet presentations get their own scenes and UIWindow instances, so the responder chain do not lead back to the presenter’s window. Instead, the responder chain goes up to the form sheet’s scene, then to your app instance, and your app delegate (if it is a UIResponder).

You must implement your commands and the validation overrides on your presented view controller, or on the app delegate, for them to continue working during form sheet presentations.

You are correct, I'm building the main menu in my app delegate. At present I'm only overriding validate() in the app delegate.

You must implement your commands and the validation overrides on your presented view controller,

When I implement the overrides in the presented view controller the new menu item isn't added to the main menu.

or on the app delegate, for them to continue working during form sheet presentations.

Isn't this what I'm doing already?

A fundamental difference between the fullscreen and page sheet presentations on Catalyst is that page sheet presentations get their own scenes and UIWindow instances, so the responder chain do not lead back to the presenter’s window. Instead, the responder chain goes up to the form sheet’s scene, then to your app instance, and your app delegate (if it is a UIResponder).

What is the implication of this if my menu is built in the app delegate? The new window with its own responder chain should still reach the app delegate, or am I misunderstanding?

UIMenuBuilder UIKeyCommand in Modal Sheet on Catalyst
 
 
Q