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
previewController.dataSource = [[MyDataSource alloc] initWithSomething];
Since the QLPreviewController
holds its dataSource as a weak variable, the data source immediately vanishes.
Keeping a strong reference to the dataSource helped.
I had the same problem, and I needed to call reloadData()
after I set the dataSource
to a new value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With