因此,我意识到有关使用 UIWebView 在应用程序(在 iPad 上)中显示 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,因为我真正需要做的就是显示并允许滚动。