拆分视图应用程序,在详细视图中显示 PDF,PDF 是本地存储

发布于 2024-11-07 05:49:38 字数 1332 浏览 5 评论 0原文

我正在构建一个拆分视图应用程序,使用数组的 plist,并使用 UIWebView 在 DetailViewController 中显示内容。使用下面的代码调用我的plist中的URL地址,并且该URL地址通过UIWebView在DetailViewController中显示PDF。

DetailViewController.m

NSString *mutareURL = [_detailItem description];
NSURL *url = [NSURL URLWithString:mutareURL];
[_catalog loadRequest:[NSURLRequest requestWithURL:url]];

我需要做的是将所有 PDF 放在我的项目的资源文件夹中。我可以对 RootViewController (TableView) 使用 NSArray 或 plist,但是当在 RootViewController (TableView) 中选择行时,我需要能够通过 UIWebView 在 DetailViewController 中显示 PDF。我在 DetailViewController.m 文件中尝试了此代码,但它不起作用。

NSString *path = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[_Pdf loadRequest:request];

我的 RootViewController.m 文件中有一个包含此代码的 NSLog,并且我确实看到 pdf 文件的名称显示在我的调试器中。我只是不知道如何从 RootViewController 获取它们并将它们传递到 pathforResourse"@"%@" ofType:@"pdf"]; 区域。宣传册是一个 NSArray,其中包含所有 addObject:@"nameofpdfs"正在通过。RootViewController.m

谢谢

detailViewController.detailItem = [NSString stringWithFormat:@"%@", [brochures objectAtIndex:indexPath.row]];
NSLog(@"Cell created for row: %d", [indexPath row]);
NSLog(@"brochures = %@", detailViewController.detailItem);

I have a Split View App that I am building, using a plist for my Array, and using a UIWebView to display content in the DetailViewController. Using the below code to make calls to the URL address in my plist, and the URL Address is displaying a PDF in the DetailViewController through the UIWebView.

DetailViewController.m

NSString *mutareURL = [_detailItem description];
NSURL *url = [NSURL URLWithString:mutareURL];
[_catalog loadRequest:[NSURLRequest requestWithURL:url]];

What I need to do is have all of the PDF's in my resource folder in my project. I can use an NSArray or plist for the RootViewController (TableView), but I need to have the ability to display the PDF's in the DetailViewController through the UIWebView when a Row is selected in the RootViewController (TableView). I tried this Code in my DetailViewController.m file, but it is not working.

NSString *path = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[_Pdf loadRequest:request];

I have an NSLog in my RootViewController.m file with this code, and i do see that the names of the pdf files are showing up in my debugger. I just do not know how to get them from the RootViewController and pass them into the pathforResourse"@"%@" ofType:@"pdf"]; area. brochures is an NSArray that has all of the addObject:@"nameofpdfs" that is passing.

RootViewController.m

detailViewController.detailItem = [NSString stringWithFormat:@"%@", [brochures objectAtIndex:indexPath.row]];
NSLog(@"Cell created for row: %d", [indexPath row]);
NSLog(@"brochures = %@", detailViewController.detailItem);

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍白女子 2024-11-14 05:49:38

答案可能就在最后一个片段中。第一行本质上是通过设置后者的 detailItem 属性,将选定的文件名从 RootViewController 传递到 DetailViewController

如果你替换

NSString *path = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"pdf"];

NSString *path = [[NSBundle mainBundle] pathForResource: self.detailItem ofType:@"pdf"];

应该可以工作。

根据 brochures 数组中的文件名是否已包含 @".pdf" 后缀,您可能必须将其从消息发送中删除:

NSString *path = [[NSBundle mainBundle] pathForResource: self.detailItem ofType: nil];

The answer is probably in the last snippet. The first line essentially passes the selected filename from the RootViewController to the DetailViewController by setting the latter's detailItem property.

If you replace

NSString *path = [[NSBundle mainBundle] pathForResource:@"%@" ofType:@"pdf"];

by

NSString *path = [[NSBundle mainBundle] pathForResource: self.detailItem ofType:@"pdf"];

it should work.

Depending on whether the filenames in the brochures array already contain the @".pdf" suffix, you might have to leave it out of the message send:

NSString *path = [[NSBundle mainBundle] pathForResource: self.detailItem ofType: nil];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文