1
votes

I am trying something that should be simple, but I'm missing something obvious, I think.

I am simply trying to load a series of PDFs into a QuickLook preview. The file names are listed in a plist file, so first I load the contents of the plist and loop through it making an array of the filenames. Then I want to just pass that array to a QuickLook preview and send the preview to the navigation controller.

This worked for me by first passing the list of files to a tableview and then when you click on a table cell, it opens the preview at the index of the cell you click on.

My goal is to eliminate the tableview, and just load the preview at the index of zero.

My suspicion is that I'm passing the wrong kind of array, or the wrong kind of filepath (I think I'm trying to send an array of NSURLs, but maybe that's the wrong thing to do).

In any case, the app builds OK and launches. But as soon as it tries to load the QuickLook preview, it hangs.

Can anybody please tell me what I'm missing here?


// issueName is the basename of the plist file...

NSString *path = [[NSBundle mainBundle] pathForResource:issueName ofType:@"plist"];
NSArray *documentSpecs = [[NSArray alloc] initWithContentsOfFile:path];

NSString *documentName = [[NSString alloc]init];
NSURL *documentURL = [[NSURL alloc]init];

for (NSString *documentSpec in documentSpecs) {
    NSArray *components = [documentSpec componentsSeparatedByString:@";"];
    documentName = components[0];

    documentURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:documentName ofType:@"pdf"]];

    [documentURLs addObject:documentURL];
}

docURLs = [NSArray arrayWithArray:documentURLs];


QLPreviewController *preview = [[QLPreviewController alloc] init];
preview.dataSource = self;
preview.currentPreviewItemIndex = 0;

[[self navigationController] pushViewController:preview animated:YES];

By the way, I did add a QuickLook data source, or at least I think I did, but maybe I messed this up:


 #pragma mark - QuickLook Preview Data Source

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

 - (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
 {
     return self.docURLs[index];
 }

Can somebody help me out with this? Thanks!

Use the file manager to verify the files exist at each path.Wain
Did you NSLog your fileURLs? Do they look like file:///var/mobile/Applications/CB596069-5DAF-40A8-93CC-E3D98E1D8A90/YOUR_APP_NAME/YOUR_FILE_NAME.pdf? What error message do you get?Marc