【发布时间】:2014-01-27 16:00:30
【问题描述】:
我正在尝试在 UIWebview 中显示 pdf,但出现错误。谁能帮我解释为什么这不起作用?错误是:
* 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'* -[NSURL initFileURLWithPath:]: nil string parameter'
每个字符串都是正确的,除了 path 似乎是 0 长度,我不知道为什么。
NSArray *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [docPath objectAtIndex:0];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 700, 500)];
NSString *path = [[NSBundle mainBundle] pathForResource:@"pdfDoc" ofType:@"pdf" inDirectory:documentDirectory];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
【问题讨论】: