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