19

我有一个 VC“A”,它以模态方式呈现 VC“B”。B 提出 a协议在 B 中实现UIDocumentMenuViewControllerUIDocumentMenuDelegate

一旦documentMenuWasCancelled(_ documentMenu:)ordocumentMenu(_:didPickDocumentPicker:)被调用dismiss(animated:completion:)B 被调用,我不知道为什么。

这是我的代码

func presentDocumentPicker() {
    let documentTypes = [
        kUTTypeCompositeContent as String,
        kUTTypePDF as String,
        "com.microsoft.word.doc",
        "vnd.openxmlformats-officedocument.wordprocessingml.document"
    ]
    let documentMenuViewController = UIDocumentMenuViewController(documentTypes: documentTypes, in: .import)
    documentMenuViewController.delegate = self
    present(documentMenuViewController, animated: true, completion: nil)
}

// MARK: - Document Menu View Controller Delegate

func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
    print("did pick")
}

func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
    print("was cancelled")
}

如您所见,我在实现的委托函数中什么都不做。仍然 B 被解雇了。我不明白。

4

1 回答 1

1

这是由documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL)单击操作或取消时调用的方法引起的UIDocumentMenuViewController

我在这里发布了一个解决方案:https ://stackoverflow.com/a/45505488/6381503

希望能帮助到你。

于 2017-08-04T11:27:26.160 回答