首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用UIDocumentPickerViewController时没有回调

使用UIDocumentPickerViewController时没有回调
EN

Stack Overflow用户
提问于 2018-11-20 10:20:08
回答 2查看 1K关注 0票数 1

我使用UIDocumentPickerViewController从iPhone中选择一个文档。

我以以下方式实现了这个特性。

代码语言:javascript
复制
class Si3EntityDocumentViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIDocumentInteractionControllerDelegate, UIDocumentPickerDelegate, UINavigationControllerDelegate, UIDocumentMenuDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        setLoader()
        getDocuments(id:entity.id)
        let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
        button.backgroundColor = .red
        button.setTitle("Upload Doc", for: .normal)
        button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
        self.view.addSubview(button)
        // Do any additional setup after loading the view.
    }

    @objc func buttonAction(sender: UIButton!){
        let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText),String(kUTTypeContent),String(kUTTypeItem),String(kUTTypeData)], in: .import)
        documentPicker.delegate = self
        present(documentPicker, animated: true, completion: {
            documentPicker.delegate = self
        } )
    }

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

}

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt url: URL)方法在iOS 11中被废弃,所以我用func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])替换了它

出于某种原因,我无法在func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL])中得到回调

这个类中还有一些其他代码,但我没有包括它。选择文档或单击“取消”时,控制台中会出现以下错误

DocumentManager视图服务终止时出现了错误: Domain=_UIViewServiceErrorDomain Code=1 "(null)“UserInfo={Terminated=disconnect方法}

我知道我错过了一些很愚蠢的东西,任何帮助都是值得感激的。

感谢你的期待。

EN

回答 2

Stack Overflow用户

发布于 2018-11-20 10:57:53

您可以查看苹果文档以获得更好的理解。

UIDocumentPickerViewController的默认行为是选择一个文档,您必须使用:

代码语言:javascript
复制
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
}

如果使用allowsMultipleSelection选择多个文档,则必须将UIDocumentPickerViewController属性设置为true并实现

代码语言:javascript
复制
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
}

另外,下面一行就足够了。

代码语言:javascript
复制
present(documentPicker, animated: true)
票数 0
EN

Stack Overflow用户

发布于 2019-09-21 10:47:49

试试看一个装置。当我登录到iCloud并试图查看目录时,模拟器没有为我工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53390825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档