2011-05-13 27 views
0

我有一個拆分視圖應用程序,我正在構建,使用plist作爲我的數組,並使用UIWebView在DetailViewController中顯示內容。使用下面的代碼調用我的plist中的URL地址,URL Address通過UIWebView在DetailViewController中顯示PDF。拆分視圖應用程序,在詳細信息視圖中顯示PDF,PDF的本地存儲

DetailViewController.m

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

我需要做的是所有的PDF文件在我的項目我的資源文件夾。我可以爲RootViewController(TableView)使用NSArray或plist,但是我需要能夠在RootViewController(TableView)中選擇Row時通過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]; 

我有一個NSLog的與此代碼我RootViewController.m文件,我看到的是,PDF文件的名稱都出現在我調試了。我只是不知道如何從RootViewController中獲取它們,並將它們傳遞到pathforResourse「@」%@「ofType:@」pdf「]; area。小冊子是一個包含所有addObject:@」nameofpdfs「的NSArray在流逝。

RootViewController.m

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

謝謝

回答

0

答案很可能是在過去的片段。第一行主要通過設置後者的傳遞從RootViewControllerDetailViewController選定的文件名detailItem財產。

如果更換

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

非常感謝你,我不知道,我可以把self.detailItem in。我必須使用nil作爲ofType。 – Rogerpn 2011-05-15 18:57:32

相關問題