如何在ios上的quicklook视图上显示导航栏?

时间:2013-08-08 13:41:12

标签: ios objective-c quicklook

我的应用程序中有一个控制器负责加载csv文件的quicklook视图。文件加载得很好,我能够无错误地渲染quicklook视图。我面临的问题是让用户能够关闭quicklook视图。

我试图只渲染一个带有关闭按钮的导航栏,作为快速查看的视图的一部分。导航栏未显示。我在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];

1 个答案:

答案 0 :(得分:0)

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