I have a controller in my application that is responsible for loading a quicklook view of a csv file. The file loads just fine and I'm able to render the quicklook view without error. The problem I'm facing is now giving the user the ability to close the quicklook view.
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. 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];