0

我可以像这样访问和显示来自 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
4

1 回答 1

1

如果您从“self.localFilename”中获得正确的文件名,那么您只需将其传递给您的文件,如下所示:

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

于 2013-02-19T09:13:46.807 回答