小编Aks*_*eni的帖子

UIDocumentPickerViewController - 未调用委托方法

我正在使用 UIDocumentPickerViewController 从文件中选择文档并将其上传到服务器。我能够成功访问文件,但是在单击文件时,不会调用委托方法。

我使用以下代码来调用文档选择器:

class Uploads: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func uploadDocument(_ sender: Any) {

        let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypePDF), String(kUTTypePlainText)], in: .import)
        documentPicker.delegate = self
        if #available(iOS 11.0, *) {
            documentPicker.allowsMultipleSelection = false
        } else {
        }
        present(documentPicker, animated: true, completion: nil)
    }

    /*
    // MARK: - Navigation

    // In …
Run Code Online (Sandbox Code Playgroud)

delegates ios swift uidocumentpickerviewcontroller

5
推荐指数
1
解决办法
1821
查看次数