Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIDocumentMenuViewController dismisses presenting view controller

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.

like image 427
Lukas Würzburger Avatar asked Mar 27 '17 17:03

Lukas Würzburger


People also ask

What happens when you dismiss a view controller?

The block to execute after the view controller is dismissed. This block has no return value and takes no parameters.

How do you dismiss the presenting view controller?

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.


1 Answers

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.

like image 76
Shkelzen Avatar answered Sep 19 '22 07:09

Shkelzen