简体   繁体   English

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

[英]How do I show a navigation bar on top of quicklook view on ios?

I have a controller in my application that is responsible for loading a quicklook view of a csv file. 我的应用程序中有一个控制器,负责加载csv文件的快速查看视图。 The file loads just fine and I'm able to render the quicklook view without error. 该文件可以很好地加载,并且我能够呈现Quicklook视图而不会出现错误。 The problem I'm facing is now giving the user the ability to close the quicklook view. 我现在面临的问题是使用户能够关闭quicklook视图。

I was trying to just render a navigation bar with a close button as part of the view that is rendering quick look. 我试图只渲染带有关闭按钮的导航栏,作为呈现快速外观的视图的一部分。 The navigation bar does not show up. 导航栏不显示。 I'm setting the elements after viewDidLoad. 我在viewDidLoad之后设置元素。 Here is the code from my controller. 这是我控制器的代码。

#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

------ I've tried this ----- Doesn't seem to be doing the trick ------我已经尝试过这个-----似乎并没有解决问题

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];

Don't directly show the preview controllers view. 不要直接显示预览控制器视图。 Instead, push the preview controller into the navigation controller stack and a navigation bar will automatically be shown with a done button (which will call the delegate when appropriate). 相反,将预览控制器推入导航控制器堆栈中,导航栏将自动显示为带有完成按钮(将在适当时调用委托)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM