how to display and where to display a pdf file by considering filePath in swift 3?

瘦欲@ 提交于 2019-12-11 15:30:05

问题


I am new to iOS development. In my project i am displaying a exerciseFilePath on tableview. the response is given below.

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

i need to display the pdf in another view on didSelectRowAtIndexpath. i Dont know how to display the pdf and what are steps to be followed to display that pdf. I hope you understand my problem. please help me how I can do this.


回答1:


Why don't you use QLPreviewController or UIDocumentInteractionController?

Now in your case you can do it by using 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)

Some tutorials:

QLPreviewController example

UIDocumentInteractionController example



来源:https://stackoverflow.com/questions/45229512/how-to-display-and-where-to-display-a-pdf-file-by-considering-filepath-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!