UIDocumentMenuViewController关闭呈现视图控制器。

20

我有一个VC "A",它以模态方式呈现VC "B"。B呈现了一个UIDocumentMenuViewControllerUIDocumentMenuDelegate协议在B中实现。

一旦调用了documentMenuWasCancelled(_ documentMenu:)documentMenu(_:didPickDocumentPicker:),就会调用B的dismiss(animated:completion:)方法,但我不知道为什么。

这是我的代码

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仍被关闭了。我不理解。


你能发送更多的项目或至少是你那里的全部ViewControllers吗? - George Bafaloukas
实际上,现在我无法复现它:D - Lukas Würzburger
你可能存在如何呈现两个控制器的问题。 - Dimple Shah
@lukwuerz,我在模拟器中也遇到了同样的问题。只要我在UIDocumentMenuViewController中进行任何操作,视图B就会关闭。你能否获取更多关于这个问题的信息?它是否又出现了?只发生在模拟器上还是真实设备上也有? - Bocaxica
1个回答

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

我在这里发布了一个解决方案:https://dev59.com/Q53ha4cB1Zd3GeqPRkJ3#45505488

希望能对您有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接