2013-02-19 3 views
0

я могу получить доступ и отобразить файл с Xcode пачки так:Json и Bundle ресурс 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

ответ

1

Если вы получаете правильное имя файла из «self.localFilename», то вам нужно ничего не делать, но передать его в файл как:

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

+0

Спасибо! теперь работает. Вот код. Он не работал, потому что мне нужно было добавить self.localFileName = @ ""; Я редактировал мой код вверх. – user1120680

+0

Еще раз спасибо за помощь. Теперь моя следующая проблема - когда я покидаю этот экран, у меня все еще есть основной экран. он не просто возвращается к моему списку меню. – user1120680

+0

Новая проблема! Кажется, что код вызывает один и тот же файл PDF каждый раз. есть идеи? спасибо – user1120680

Смежные вопросы