2015-09-07 26 views
0

我試圖加載PDF文件,該文件是在我的Xcode項目我使用這個代碼的Web視圖ViewDidLoad廣東話載入本地PDF文件到的WebView

var pdfLoc = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("Anteproyecto", ofType:"pdf")!) 
    var request = NSURLRequest(URL: pdfLoc!) 
    webView.loadRequest(request) 

昨天它的工作,但今天它crsahes並在日誌中顯示此錯誤

DiskImageCache: Could not resolve the absolute path of the old directory. 

我在做什麼錯?

回答

0

請試試這個

var path: String = NSBundle.mainBundle().pathForResource(fileName, ofType: "pdf") 
var targetURL: NSURL = NSURL.fileURLWithPath(path) 
var request: NSURLRequest = NSURLRequest.requestWithURL(targetURL) 
self.webView.loadRequest(request) 

我希望它會工作。

+0

我試過了,但仍然出現同樣的崩潰 – Zablah

+0

請嘗試調試一個pdf文件是否存在路徑或不。爲此,從路徑變量中獲取路徑並返回到查找器Go->轉到文件夾。 –