【问题标题】:Using Document Browser View Controller with Mac Catalyst在 Mac Catalyst 中使用文档浏览器视图控制器
【发布时间】:2020-02-07 20:32:52
【问题描述】:

我刚刚开始尝试使用 Catalyst。我的应用是基于文档浏览器的应用。

当点击相应的按钮时,MacOS Finder 对话框确实会启动。当 Finder 对话框出现时,主应用程序窗口完全消失,除非我在 IB 中选择让文档浏览器视图控制器以“自动”模式出现。

取消操作确实会返回主窗口。

但是,选择一个文件会产生一个空白屏幕并且没有结果。稍微调试一下,发现没有调用任何文件选择函数,我已经实现了所有这些函数:

func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) {...}

func documentBrowser(_ controller: UIDocumentBrowserViewController, didImportDocumentAt sourceURL: URL, toDestinationURL destinationURL: URL) {...}

func documentBrowser(_ controller: UIDocumentBrowserViewController, failedToImportDocumentAt documentURL: URL, error: Error?) {...}

Catalyst 中是否使用了其他函数或句柄?我在文档中一无所获。

编辑: 我应该澄清一下,我操纵应用程序在 DocumentBrowserViewController 之前显示 DocumentViewController,尽管 Apple 要求 DocumentBrowserViewController 是初始视图控制器。我通过更改应用程序委托来做到这一点:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

...

// Set the documentViewController to appear first
    self.window = UIWindow(frame: UIScreen.main.bounds)

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let initialViewController = storyboard.instantiateViewController(withIdentifier: "main")

    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()

    return true
}

取出它仍然不会改变任何东西。从文档浏览器模板创建的默认项目似乎确实有效。什么可以阻止这些方法被调用?

【问题讨论】:

    标签: swift browser document mac-catalyst uidocumentbrowserviewcontroller


    【解决方案1】:

    我建议也实现func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL])

    【讨论】:

    • 这确实是缺少的功能。我的下一个问题与这个问题无关 - 加载文件后 viewController 不在视图层次结构中,尽管将其设为根视图控制器并使用 makeKeyAndVisible。有什么想法吗?
    • 我怀疑这可能与您在 DocumentBrowserViewController 之前显示 DocumentViewController 有关,因为根据我自己的经验,我猜 MacCatalyst 使用 DocumentBrowserViewController 作为一些入口点。抱歉,我无法就这个问题提供太多意见
    • 找到了答案——在 iPad 版本中,我通过调用 makeKeyAndVisible 切换了视图控制器,以清除之前视图控制器的所有痕迹。在 MacCatalyst 中,这只能在应用程序委托中工作一次。之后,当你想切换到一个新的视图控制器时,你必须使用 present 方法。
    猜你喜欢
    • 2011-02-09
    • 2018-04-17
    • 2011-03-23
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    • 2013-08-28
    相关资源
    最近更新 更多