如何在swift 3中考虑filePath来显示和显示pdf文件?

我是iOS开发新手。 在我的项目中,我在tableview上显示exerciseFilePath。 回应如下。

"exerciseId" : 1, "exerciseName" : "Fitness Exercise", "exerciseFilePath" : "\/p\/pdf\/exercise_pdf\/fitness_exercise.pdf" 

我需要在didSelectRowAtIndexpath的另一个视图中显示PDF。 我不知道如何显示PDF,以及要遵循的步骤来显示该PDF。 我希望你能理解我的问题。 请帮助我如何做到这一点。

为什么不使用QLPreviewController或UIDocumentInteractionController ?

现在在你的情况下,你可以通过使用webView来做到这一点:

 let req = NSURLRequest(url: pdf) //pdf is your pdf path let webView = UIWebView(frame: CGRect(x:0,y:0,width:self.view.frame.size.width,height: self.view.frame.size.height-40)) //Adjust view area here webView.loadRequest(req as URLRequest) self.view.addSubview(webView) 

一些教程:

QLPreviewController示例

UIDocumentInteractionController示例