我正在尝试使用iOS应用程序显示位于我们网站上的PDF文件。这是我的做法:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
print("preparing segue")
if segue.identifier == "PdfWebView" {
print("Found segue")
let detailViewController = segue.destinationViewController as! PdfViewController
let myIndexPath = self.tableView.indexPathForSelectedRow!
let row = myIndexPath.row
//Pass selected cell title to next View
detailViewController.website = pdfLinks[row]
print("Website: ", detailViewController.website)
}
}
// 这段代码位于pdfViewController中
// 网站链接 = http://www.example.com/some-pdf-document-to-display.pdf
if let website = website {
print("Getting pdf: ",website)
if let pdf = NSBundle.mainBundle().URLForResource(website, withExtension: "pdf", subdirectory: nil, localization: nil){
print(pdf) // <-- this is always nil
let req = NSURLRequest(URL: pdf)
webView.loadRequest(req)
self.view.addSubview(webView)
}
}
我做错了什么?不用说,这是我开发的第一个应用程序。
相关的技术方面内容请提供更多细节信息。