我刚刚开始试用 Catalyst。我的应用程序是一个基于文档浏览器的应用程序。
单击适当的按钮时,确实启动了原装 MacOS Finder 对话框。当 Finder 对话框出现时,主应用程序窗口完全消失,除非我在 IB 中选择文档浏览器 View Controller 以“自动”模式出现。
取消操作确实会返回主窗口。
但是,选择一个文件将产生一个空白屏幕并且没有结果。稍微调试一下,发现没有调用任何文件选择函数,我已经实现了所有这些函数:
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 是初始 View Controller 。我通过更改应用程序委托(delegate)来做到这一点:
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
}
把它拿出来仍然没有任何改变。从文档浏览器模板创建的默认项目似乎确实有效。什么可以阻止调用这些方法?
最佳答案
我建议也实现 func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL])
关于swift - 在 Mac Catalyst 中使用文档浏览器 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58322189/