0

I trying to open a pdf document when a UiButton called viewManual is pressed. I have added the QuickLook framework and currently have:

.h

#import <QuickLook/QuickLook.h>

@interface ObViewControllerUsingIObserve : UIViewController <QLPreviewControllerDataSource,                                                     QLPreviewControllerDelegate>
{
NSArray *documents;
}
- (IBAction)viewManual:(id)sender;
- (void)createList;
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller;
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index;

.m

-(void) createList
{
  documents = [NSArray arrayWithObjects:@"ObservationPDF.pdf", nil] ;   
}

-(NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) previewcontroller
{
return [documents count];
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) previewController previewItemAtIndex: (NSInteger) index
{

return [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[documents objectAtIndex:0] ofType:nil]];
}

- (IBAction)viewManual:(id)sender {
[self createList];
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.delegate = self;
previewController.currentPreviewItemIndex = [documents objectAtIndex:0];
[[self navigationController] presentViewController: previewController animated:YES completion:nil];

}

I have tried this following code from a previous thread but it does not work for, nothing happens at all, and I am not sure where I go from here. Any help much appreciated.

RGriffiths
  • 5,722
  • 18
  • 72
  • 120
  • You need code to download the file. Also, the file URL must be complete path, not just the name of the file. – Wain Jun 06 '13 at 06:01
  • I am still confused. I have added the [self createList] to load the document name into the list. The file is now saved in the project but still nothing happens. It runs without any errors but no pdf view is presented. Thank you for your help. – RGriffiths Jun 06 '13 at 11:30
  • So the PDF is installed with the app as part of the resources? – Wain Jun 06 '13 at 12:24
  • It is for the moment - I am just trying to get the viewer to work. Once that is sorted I will get the link to take the pdf from the website. – RGriffiths Jun 06 '13 at 13:10
  • debugged to check the file URL and that the file exists at the specified path? – Wain Jun 06 '13 at 13:16
  • Yes the file exists and documents ObjectAtIndex 0 loads the file name correctly. Thanks again - I really appreciate you help with this. – RGriffiths Jun 06 '13 at 13:45

1 Answers1

0

I am new to iOS development. (3 days in) So I don't know if this will help, but if your QLPreviewController implements a protocol, the protocol defines a set of methods that MUST be implemented.

It seems that you have not implemented these methods (numberOfPreviewItemsInPreviewController and previewItemAtIndex) therefore your controller does not conform to the protocol requirements.

I will take a look at the QuickLook framework and see if I can find out more.

Daniel Retief Fourie
  • 626
  • 2
  • 10
  • 20
  • Thanks or your comment. I am still trying to figure it out and appreciate your help. – RGriffiths Jun 05 '13 at 23:35
  • Pleasure! Hope it points you in the right direction. I'm slowly starting to understand the iOS complexities in the underlying patterns, so I will keep checking back and try to assist. Good luck! – Daniel Retief Fourie Jun 06 '13 at 07:54