2013-02-19 73 views
0

我可以訪問和顯示來自Xcode的捆綁像這樣的文件:JSON和捆綁資源的Xcode

NSString *file = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"pdf"]; 

現在我想要做的就是使用此JSON這確實給我拿在文件的名稱填寫正確的名稱:

self.localFileName = [BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"localFileName":@""]; 

如何將這兩個東西放在一起,以便我可以使用JSON名稱調用捆綁文件?

這裏是整個事情:

// 
// ReaderDemoController.m 
// PDFViewer 
// 
// Created by C. A. Beninati on 5/21/12. 
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. 
// 
//BT imports 
#import <UIKit/UIKit.h> 
#import <Foundation/Foundation.h> 
#import <MediaPlayer/MediaPlayer.h> 
#import "JSON.h" 
#import "BT_strings.h" 
#import "testapp_appDelegate.h" 
#import "BT_fileManager.h" 
#import "BT_color.h" 
#import "BT_viewUtilities.h" 
#import "BT_downloader.h" 
#import "BT_item.h" 
#import "BT_debugger.h" 
#import "BT_viewControllerManager.h" 

#import "ReaderDemoController.h" 
#import "ReaderViewController.h" 

@interface ReaderDemoController()<ReaderViewControllerDelegate> 

@end 

@implementation ReaderDemoController 
@synthesize localFileName; 


- (void)viewDidLoad 
{ [BT_debugger showIt:self:@"ZZZZZZZZZZ!!!"]; 
    [super viewDidLoad]; 

    self.localFileName = [BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"localFileName":@""]; 

    self.localFileName = @""; // added this to make it work!! 

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

    ReaderDocument *document = [ReaderDocument withDocumentFilePath:file password:nil]; 

    if (document != nil) 
    { 
     ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document]; 
     readerViewController.delegate = self; 

     readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
     readerViewController.modalPresentationStyle = UIModalPresentationFullScreen; 

     [self presentModalViewController:readerViewController animated:YES]; 
    } 

} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 




- (void)dismissReaderViewController:(ReaderViewController *)viewController { 
    [self dismissModalViewControllerAnimated:YES]; 
} 

@end 
+0

我在正確的軌道上嗎? NSString * file = [[NSBundle mainBundle] pathForResource:self.localFileName ofType:@「pdf」]; – user1120680 2013-02-19 08:31:49

回答

1

如果從「self.localFilename」得到正確的文件名,那麼你需要做什麼,但它傳遞給你的文件爲:

NSString * file = [[NSBundle mainBundle] pathForResource:self.localFileName ofType:@「pdf」];

+0

謝謝!它現在正在工作。這是代碼。它不工作,因爲我需要添加self.localFileName = @「」;我編輯我的代碼頂部。 – user1120680 2013-02-19 16:21:47

+0

再次感謝您的幫助。現在我的下一個問題是當我離開這個屏幕時,我仍然有一個底層屏幕顯示。它不只是回到我的菜單列表。 – user1120680 2013-02-19 16:26:34

+0

新問題!看起來代碼每次都調用同一個PDF文件。有任何想法嗎?謝謝 – user1120680 2013-02-19 21:15:02