我有一个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仍然被解雇了。我不明白。
答案 0 :(得分:0)
这是由documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL)
方法导致的,当您点击某个操作或取消UIDocumentMenuViewController
时会调用该方法。
我在这里发布了一个解决方案:https://stackoverflow.com/a/45505488/6381503
希望它有所帮助。