拆分视图应用程序,在详细视图中显示 PDF,PDF 是本地存储
我正在构建一个拆分视图应用程序,使用数组的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案可能就在最后一个片段中。第一行本质上是通过设置后者的
detailItem
属性,将选定的文件名从RootViewController
传递到DetailViewController
。如果你替换
它
应该可以工作。
根据
brochures
数组中的文件名是否已包含@".pdf"
后缀,您可能必须将其从消息发送中删除:The answer is probably in the last snippet. The first line essentially passes the selected filename from the
RootViewController
to theDetailViewController
by setting the latter'sdetailItem
property.If you replace
by
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: