2

I have a multi-window scene-based (not SwiftUI) iPad app that I am adapting for Mac using mac catalyst. I am having trouble with the main menu behavior. The menu is built in AppDelegate.swift using func buildMenu(). I have, for example, an Open Image... menu item that uses a selector in my main view controller. Here is the code in buildMenu():

 let openFileCommand = UIKeyCommand(
            title: "Open Image...",
            action: #selector(DiagramViewController.openImageFile(_:)),
            input: "o",
            modifierFlags: [.command]
        )
        let openFileMenu = UIMenu(
            title: "",
            image: nil,
            identifier: UIMenu.Identifier("openImage"),
            options: .displayInline,
            children: [openFileCommand]
        )
        builder.insertSibling(openFileMenu, afterMenu: .newScene)

It is enabled and works fine when first opening the view controller. See: Open Image... menu item activated

I then open any modal dialog, for example, the About dialog, and after closing it, the Open Image... menu item is deactivated, as if the selector is no longer in the responder chain, though everything works on the view controller.

Open Image... menu item is deactivated

I don't understand what is going on here. This kind of functionality works fine on a non-multi-window catalyst app.

UPDATE: Well the problem has nothing to do with the app being scene-based. It is a UIDocument based app, and the UIDocumentBrowserViewController presents the main view controller modally. The main view controller is then the first responder and everything is fine, but as soon as you open another modal window on top of it, like the system generated About dialog, the original document browser view controller becomes the first responder and the main view controller is no longer in the window hierarchy (even though the document browser view controller is invisible, and the main view controller is still shown and works normally). If anyone has experience with dealing with this issue, I'd appreciate their advice.

David Mann
  • 31
  • 2

1 Answers1

0

With further experimentation, and given that this is a UIDocument based app, it looks like the document browser view controller becomes the first responder after the dialog closes. So I think I can work around that and forward actions form the document browser to the main view controller.

David Mann
  • 31
  • 2