1

In one VC I am working in there are three buttons, and each button should present a document picker for different types of media. I have this configured-- but what I am not sure how to do is to handle my delegate method

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {

How can I monitor which document picker set off the delegate method, since every button should handle this function differently? I tried to use controller.tag, but this doesn't seem to be a property of a UIDocumentPickerViewController. Any pointers would be much appreciated thanks.

1 Answer 1

1

You can create 3 separate instances of UIDocumentPickerViewController in your view controller and check the instance of controller in delegate method.

private lazy var documentPicker1: UIDocumentPickerViewController = {
    let controller = UIDocumentPickerViewController()
    controller.delegate = self
    return controller
}()

private lazy var documentPicker2: UIDocumentPickerViewController = {
    let controller = UIDocumentPickerViewController()
    controller.delegate = self
    return controller
}()

private lazy var documentPicker3: UIDocumentPickerViewController = {
    let controller = UIDocumentPickerViewController()
    controller.delegate = self
    return controller
}()

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    
    if controller == documentPicker1 {

    } else if controller == documentPicker2 {

    }
    ...
}

Or you could keep a property in view controller to track which button was tapped and check it in the delegate method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.