I have a VC "A" that present VC "B" modally. B presents a UIDocumentMenuViewController
The UIDocumentMenuDelegate
protocol is implemented in 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.
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. I don't get it.
The block to execute after the view controller is dismissed. This block has no return value and takes no parameters.
When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing 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
.
I posted a solution here: https://stackoverflow.com/a/45505488/6381503
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With