【问题标题】:view PDF in UIWebView在 UIWebView 中查看 PDF
【发布时间】:2012-11-19 23:54:37
【问题描述】:

我的应用程序的“支持文件”文件夹包含一个名为 test.pdf 的文档。 尝试在ViewDidLoad 中使用以下代码查看 pdf 文件会显示一个空的 UIWebView:

NSString *testPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
NSURL *testURL = [NSURL URLWithString:testPath];
NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL];

UIWebView *documentWebView;

documentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 24, 300, 400)];

[documentWebView loadRequest:testRequest];

[self.view addSubview:documentWebView];

谁能告诉我为什么 PDF 没有显示在 Web 视图中?谢谢。

【问题讨论】:

  • 该 pdf 文件是否已添加到您的 xcode 中?
  • 是的,在“支持文件”文件夹中。
  • 尝试删除并重新添加。还要检查 Target -> “Build Phases” -> “copy bundle Resources” 并确保它存在
  • 感谢您的建议。我尝试删除并再次添加,文档在 Build Phases 中列出,但没有任何乐趣。
  • 这能解决您的问题还是您仍然面临它?

标签: ios pdf uiwebview


【解决方案1】:

这一行:

NSURL *testURL = [NSURL URLWithString:testPath];

需要:

NSURL *testURL = [NSURL fileURLWithPath:testPath];

【讨论】:

  • 真的非常感谢你,而且发现得很好。这让我发疯了好几个小时。 =)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-02
  • 2013-06-16
  • 2012-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-19
相关资源
最近更新 更多