简体   繁体   English

UIDocumentMenuViewController取消呈现视图控制器

[英]UIDocumentMenuViewController dismisses presenting view controller

I have a VC "A" that present VC "B" modally. 我有一个VC“A”模式提供VC“B”。 B presents a UIDocumentMenuViewController The UIDocumentMenuDelegate protocol is implemented in B. B呈现UIDocumentMenuViewController UIDocumentMenuDelegate协议在B中实现。

As soon as documentMenuWasCancelled(_ documentMenu:) or documentMenu(_:didPickDocumentPicker:) gets called the dismiss(animated:completion:) of B gets called and i have no clue why. 一旦documentMenuWasCancelled(_ documentMenu:)documentMenu(_:didPickDocumentPicker:)被调用,B的dismiss(animated:completion:)就被调用,我不知道为什么。

Here's my code 这是我的代码

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")
}

As you can see I do nothing in the implemented delegate function. 如您所见,我在实现的委托函数中什么都不做。 And still B gets dismissed. B仍然被解雇了。 I don't get it. 我不明白。

This is caused by documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) method which is called when you click on an action or when you cancel UIDocumentMenuViewController . 这是由documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL)方法引起的,当您单击某个操作或取消UIDocumentMenuViewController时会UIDocumentMenuViewController

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

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM