UIDocumentMenuViewController取消呈现视图控制器

时间:2017-03-27 17:45:57

标签: ios swift uiviewcontroller presentmodalviewcontroller uidocumentmenuvc

我有一个VC“A”,它以模态方式呈现VC“B”。 B显示UIDocumentMenuViewController UIDocumentMenuDelegate协议在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仍然被解雇了。我不明白。

1 个答案:

答案 0 :(得分:0)

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

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

希望它有所帮助。