I am trying to preview pdf file in QLPreviewController and using the below code. It works fine on iOS7 and for other type of files (JPG/PNG) on iOS8 as well but when I try to open pdf it shows blank page instead content on iOS8. Its weird that it still shows name of pdf in title view.
Code:
QLPreviewController *previewer = [[QLPreviewController alloc] init];
previewer.dataSource = self;
previewer.currentPreviewItemIndex = 0;
[self presentViewController:previewer animated:NO completion:nil];
And QLPreviewControllerDataSource methods:
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
return 1;
}
- (id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
return [NSURL fileURLWithPath:self.pdfUrl];
}
I just recently encountered a blank page again and I have found the reason to be that I did something like
Since the
QLPreviewController
holds its dataSource as a weak variable, the data source immediately vanishes.Keeping a strong reference to the dataSource helped.
For iOS 9.2: In Monotouch.ios,
use
instead of
It will work for all files. (jpg,png,pdf,etc)
Use this code if you in desperate need to use QLPreviewController embedded in UINavigationController: