0

我的应用程序中有一个控制器,负责加载 csv 文件的快速查看视图。该文件加载得很好,我能够毫无错误地呈现快速查看视图。我现在面临的问题是让用户能够关闭快速查看视图。

我试图只呈现一个带有关闭按钮的导航栏,作为呈现快速外观的视图的一部分。导航栏不显示。我在 viewDidLoad 之后设置元素。这是我的控制器的代码。

#import "JornadaDocPreviewViewController.h"

@interface JornadaDocPreviewViewController ()

@end

@implementation JornadaDocPreviewViewController

-(id)initWidthArray:(NSArray*)array;
{
    self = [super init];

    if(self)
    {
        arrayOfDocuments = array;

    }

    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.dataSource = self;

    // Which item to preview
    [self setCurrentPreviewItemIndex:0];

    self.delegate = self;
    UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close"
                                                                    style:UIBarButtonItemStylePlain
                                                                   target:self
                                                                   action:@selector(closeThis)];

    NSArray *myToolbarItems = [NSArray arrayWithObjects:closeButton, nil];
    self.toolbarItems = myToolbarItems;




}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.toolbarHidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.toolbarHidden = YES;
}

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
    return [arrayOfDocuments count];
}

/*---------------------------------------------------------------------------
 *
 *--------------------------------------------------------------------------*/
- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    // Break the path into its components (filename and extension)
    NSArray *fileComponents = [[arrayOfDocuments objectAtIndex: index] componentsSeparatedByString:@"."];


    // Use the filename (index 0) and the extension (index 1) to get path
    NSString *path = [[NSBundle mainBundle] pathForResource:[fileComponents objectAtIndex:0] ofType:[fileComponents objectAtIndex:1]];

    NSLog(@"path %@", [fileComponents objectAtIndex:0]);

    return [NSURL fileURLWithPath:[arrayOfDocuments objectAtIndex: index]];
}


@end

------ 我试过这个 ----- 似乎没有成功

UIView *previewView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, self.view.frame.size.width - 20, self.view.frame.size.height - 20)];

    //[self.view addSubview:previewView];

    JornadaDocPreviewViewController *previewer = [[JornadaDocPreviewViewController alloc] initWidthArray:value];

    [previewView.window setRootViewController:previewer ];
    //[self.view bringSubviewToFront:previewView];

    [self.navigationController pushViewController:previewer animated:YES];
4

1 回答 1

0

不要直接显示预览控制器视图。相反,将预览控制器推入导航控制器堆栈,导航栏将自动显示一个完成按钮(它将在适当时调用委托)。

于 2013-08-08T13:51:42.540 回答