Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quicklook/QLPreviewController shows a blank page instead of pdf on ios 8 but works fine on iOS7

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];
}
like image 544
sanjana Avatar asked Aug 14 '14 11:08

sanjana


2 Answers

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.

like image 179
DrMickeyLauer Avatar answered Nov 15 '22 16:11

DrMickeyLauer


I had the same problem, and I needed to call reloadData() after I set the dataSource to a new value.

like image 22
Jason Avatar answered Nov 15 '22 17:11

Jason