【问题标题】:UIDocumentPickerViewController when initialized in a framework shows files as grayed outUIDocumentPickerViewController 在框架中初始化时将文件显示为灰色
【发布时间】:2021-05-25 21:24:20
【问题描述】:
我想从一个框架初始化一个 UIDocumentPickerViewController。但是,在框架中使用以下代码时,文件 (.pdf) 在文档选择器中显示为灰色。当 UIDocumentPickerViewController 在主应用程序目标中初始化时,代码工作正常。这是我用的。
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.pdf])
documentPicker.delegate = self
present(documentPicker, animated: true, completion: nil)
【问题讨论】:
标签:
ios
swift
uidocument
uidocumentpickerviewcontroller
【解决方案1】:
我的问题是,我试图从window.rootViewController 呈现UIDocumentPickerViewController,因为我无法从我的主要目标访问UIViewController。我在我的框架中创建了一个UIViewController 并从那里呈现UIDocumentPickerViewController 并且它起作用了。但是,我仍然不确定从window.rootViewController 呈现UIDocumentPickerViewController 与从真正的UIViewController 对象呈现有什么区别。嗯,两者都是 UIViewControllers
【解决方案2】:
由于您在框架中有UIDocumentPickerViewController,因此更好的方法是使用custom UIViewController 并在该视图控制器中实现UIDocumentPickerViewController 的所有代表。然后在您的主应用程序中,您可以继承该自定义 UIViewController 并调用父 API 以加载 UIDocumentPickerViewController。