因此,我意識到使用UIWebView在應用程序中顯示PDF(在iPad上)時存在很多問題。我已經查看了所有我能找到的東西,但我似乎無法找到任何滿意的結果。使用UIWebView無法顯示PDF
我試圖做的是很基本的,所以我真的不知道爲什麼它不工作。我需要做的就是在UIWebView中顯示本地存儲的PDF。從本質上講,我所得到的只是一個黑屏。如果有人可以看看我的代碼,我真的很感激它。謝謝。
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Segue to the materials screen.
if ([segue.identifier isEqualToString:@"materials"]) {
PDFViewController *pdfViewController = [segue destinationViewController];
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
int row = [path row];
Lesson *selected = [purchasedLessons objectAtIndex:row];
pdfViewController.selectedLesson = selected ;
//Start Load PDF in UIWebView
pdfViewController.pdfWindowTitle.title = selected.titleAndSubtitle;
pdfViewController.pdfWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 1024, 704)];
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"moonlightSonataFirstMovement" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[pdfViewController.pdfWebView loadRequest:requestObj];
//End Load PDF
}
}
我檢查,看看我的對象帶來傳遞到現場正確(這是),如果我得到一個適當的請求的;我越來越:
<NSURLRequest file://localhost/Users/MYCOMPUTER/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/AB161E57-D942-44C2-AA75-030087820BED/iLessons%20Piano.app/moonlightSonataFirstMovement.pdf>
另外,我有這樣的錯誤消息:
iLessons Piano[23080:f803] DiskImageCache: Could not resolve the absolute path of the old directory.
此外,該消息的NSLog會打印出8倍出於某種原因。
我能想到的唯一的事情是我需要的時候我在打電話前一個場景我prepareForSegue功能做到這一點加載。這或使用像Quartz一樣的不同方法。但我寧願使用UIWebView,因爲我真正需要做的是顯示並允許滾動。
只是想一想,名字是否正確?設備路徑始終區分大小寫。 – cocoakomali 2012-03-07 19:20:51
是的,我希望它只是文件名。我檢查了幾次。它匹配:(這是「moonlightSonataFirstMovement.pdf」 – Barks 2012-03-07 19:25:51
我試着將代碼移入prepareForSegue函數,但仍然沒有任何內容只是一個黑屏 – Barks 2012-03-07 20:07:20