-1

I've already attemped a WKWebView with no luck. Now I'm attempting to use QLPreviewController.

I've created a UIViewController and subclassed it under QLPreviewController.

In my viewDidLoad I set the delegate and data source:

self.dataSource = self;
self.delegate = self;
self.currentPreviewItemIndex = 0;

I then have the following two methods to get the number of items in the view controller and the file path:

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
    return 1;
}

- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
    NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"BOR" ofType:@"pdf"];
    NSURL *fileURL = [[NSURL alloc] initWithString:pdfPath];
    return fileURL;
}

When I navigate to my view controller, The view is gray and displays the following text:

"No file to preview"

What am I doing wrong?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Faisal Syed
  • 921
  • 1
  • 11
  • 25
  • add a print statement/breakpoint on your `return fileURL` -> and check that the file is at that url: `FileManager.default.fileExists(_ atPath: String)`. – Jacob Boyd Oct 11 '17 at 17:01
  • Yes the file does exist – Faisal Syed Oct 11 '17 at 17:06
  • Do not take the file's path and convert it to a URL. Take its URL (`URLForResource`). Before you return that, look to see if it is `nil`. – matt Oct 11 '17 at 17:25
  • that makes sense - however it looks like none of my delegate methods are getting called. I even added the protocols in my .h like so QLPreviewController Is this an issue with iOS 11.0? – Faisal Syed Oct 11 '17 at 17:34
  • Are you trying preview PDF documents or do you want to see them for real? (i.e. allow navigation and the such) – theMikeSwan Oct 11 '17 at 18:00
  • You don’t mean you have subclassed QLPreviewController? That is illegal and unnecessary. – matt Oct 11 '17 at 21:38

1 Answers1

0

It seems you have subclassed QLPreviewController? That is illegal and unnecessary. You just make a preview controller, configure it, and push it or present it.

matt
  • 515,959
  • 87
  • 875
  • 1,141