首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIDocument不工作

UIDocument不工作
EN

Stack Overflow用户
提问于 2017-05-13 01:15:00
回答 1查看 278关注 0票数 0

我正在尝试用下面的方法打开文档文件,但是没有任何反应。我也尝试过其他方法,但对我不起作用。打开文档文件(doc、docx、pdf、ppt等)的正确方式是什么?我在某个地方读到了UIWebView(),这也是可以做到的,那么更好的方法是什么呢?

代码语言:javascript
复制
let fileURL = URL(fileURLWithPath: documentMessage.fileUrl)

let doc = DocumentPreview(fileURL)
doc.startPreview()

DocumentPreview.swift

代码语言:javascript
复制
class DocumentPreview : NSObject, UIDocumentInteractionControllerDelegate {
    var url : URL?
    var document : UIDocumentInteractionController?
    var previewVC : UINavigationController?

    init(_ url: URL) {
        super.init()
        self.url = url
        document = UIDocumentInteractionController(url:url)
        document?.delegate = self
    }

    func startPreview(){
        document?.presentPreview(animated:true)
    }

    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
        return previewVC!
    }

    func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
        print("end Preview")
        previewVC!.popViewController(animated: true)
    }
}
EN

回答 1

Stack Overflow用户

发布于 2017-05-14 05:03:50

看看documentMessage吧。如果.fileUrl属性是一个URL,那么这个代码是错误的:

代码语言:javascript
复制
let fileURL = URL(fileURLWithPath: documentMessage.fileUrl)

最简单的解决方法是:

代码语言:javascript
复制
let fileURL = documentMessage.fileUrl
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43943212

复制
相关文章

相似问题

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