首页 > 解决方案 > UIDocumentPickerViewController 在框架中初始化时将文件显示为灰色

问题描述

我想从框架初始化 UIDocumentPickerViewController。但是,在框架中使用以下代码时,文件 (.pdf) 在文档选择器中显示为灰色。当 UIDocumentPickerViewController 在主应用程序目标中初始化时,代码工作正常。这就是我使用的。

    let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.pdf])
    documentPicker.delegate = self
    present(documentPicker, animated: true, completion: nil)

标签: iosswiftuidocumentuidocumentpickerviewcontroller

解决方案


正如您UIDocumentPickerViewController在框架中所拥有的那样,更好的方法是使用custom UIViewController和实现UIDocumentPickerViewController该视图控制器中的所有委托。然后在您的主应用程序中,您可以继承该自定义 UIViewController 并调用父 API 来加载UIDocumentPickerViewController


推荐阅读