0

This code works at first touch. Preview starts to display (Title, Done, Actions, and blank page) and then previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)index is called again. This time [self.resultsController objectAtIndexPath:selectedIndexPath]; returns nil - My guess is the entry is no longer selected. index is correct at 1.

The procedure:

- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)index
{
    NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
    Manuals *manuals = [self.resultsController objectAtIndexPath:selectedIndexPath];
    NSURL *vUrl = [self locateUrl:[NSURL URLWithString:manuals.Url] ofType:[manuals.Url pathExtension]];    
    return vUrl;
}

If I ignore the exception - the preview continues to display the the document.

I did try to keep the last good returned selectedIndexPath, but then received the error: -[__NSArrayM indexAtPosition:]: unrecognized selector sent to instance 0x1cd52800

The question:

How can I get my resultsController object using only the passed in index?

Kent
  • 1,374
  • 1
  • 15
  • 29

2 Answers2

0

The problem was in numberOfPreviewItemsInPreviewController:previewController. I was returning the [resultsController count], not the number of documents I wanted to be previewed. When the previewController tried to access the next few objects, it was returning nil.

// Returns the number of items that the preview controller should preview
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController
{
    return 1;
}
Kent
  • 1,374
  • 1
  • 15
  • 29
0

I'm not sure if this answers your question but you can use:

[previewController setCurrentPreviewItemIndex:0];

to set the current item that you want to be previewed.

JDx
  • 2,615
  • 3
  • 22
  • 33
  • I am not calling [previewController in my code. It's delegated. I am just trying to return the correct file:// url the QLPreviewController is requesting. – Kent Dec 14 '11 at 17:37