how to display and where to display a pdf file by

2019-09-16 04:32发布

问题:

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