开发者

Split View App, display PDF's in the Detail View, PDF's are local storage

开发者 https://www.devze.com 2023-03-05 23:25 出处:网络
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 m

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


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消