2014-10-28 47 views
0

在向UIWebView添加约束之前,我的应用工作正常。但是,有一个错误:添加缺失的约束后,UIWebView无法加载PDF文件

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

该应用程序仍然工作,并显示PDF文件。添加一些约束后,它不会显示pdf文件(它显示为空白),并且错误代码仍然存在。

下面是一些图片:

PIC 1:

enter image description here

PIC 2:

enter image description here

这是我的代码:

 { 
      NSString* tutorialView = [NSString stringWithFormat:@"Chapter %i",tutorialNumber]; 
      NSURL *pathToView = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:tutorialView ofType:@"pdf"]]; 
      [_webView2 loadRequest:[NSURLRequest requestWithURL:pathToView]]; 

     } 

是否有更好的方式来查看PDF文件?我是iOS编程新手。对不起,愚蠢的问题

+0

我认为有一些问题,PDF文件本身,你在做什么是正确的,你可以在UIWebView中查看PDF,请尝试使用其它PDF看看它是否工作。 – iphonic 2014-10-29 18:59:28

回答

0

请尝试以下操作。它的作品跟我完全没有问题:)

UIWebView *pdf = [[UIWebView alloc] initWithFrame:CGM(0,0, self.view.frame.size.width, self.view.frame.size.height)]; 
NSString *path = [[NSBundle mainBundle] pathForResource:@"Name Of PDF FIle" ofType:@"pdf"]; 
NSURL *targetURL = [NSURL fileURLWithPath:path]; 
pdf.scalesPageToFit = YES; 
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];<br> 
[pdf loadRequest:request]; 
[self.view addSubview:pdf];