How can I make NSToolbar on Catalyst check canPerformAction on UISplitViewController's secondary view controller instead of primary?

I have a Catalyst app that I'm adding a sidebar to via UISplitViewController. I have a toolbar on the window with buttons that I want to be enabled or disabled based on the state of the view controller in the split view's secondary column. But it seems to want to check the primary view controller instead.

In the Catalyst tutorial Adding a Toolbar, this exact approach is demonstrated. The RecipeDetailViewController has methods for toggleFavorite and editRecipe, and the toolbar items are set up to reference those selectors in the ToolbarDelegate class. In the screenshots in the tutorial, the buttons are shown as enabled based on RecipeDetailViewController.canPerformAction. But when I download and run the complete project on my computer (macOS 14.4.1), the toolbar items are disabled. And if I add the methods to the RecipeListViewController (which is in the primary column of the UISplitViewController, the toolbar items get enabled.

Is there a way to make the system ask the correct split view column for canPerformAction? Or is this a bug?

I've filed this as FB13888167, as requested in a WWDC 2024 lab.

I was given a couple of workarounds, but they aren't working super well for me yet:

  • Put the action validation and routing further up the responder chain, like the scene delegate. But even if my scene delegate inherits from UIResponder, it's not automatically in the responder chain. Even with tricks to insert it in the chain, I can't (yet) get it to work.
  • Set an explicit target on the toolbar items. But I have menu items too, and the menu items might be handled by different floating windows in my app, and I'd rather not have to re-set the targets on all those menu items every time the active window changes.
How can I make NSToolbar on Catalyst check canPerformAction on UISplitViewController's secondary view controller instead of primary?
 
 
Q