Issue with adding QLPreviewController's view as subview in iOS 10

My issue is that I was using QLPreviewController's view as a subview to my constom view controller, since I need different controls to be available on the toolbar. This is working fine till iOS 9. However in iOS10 the view does not show up the image. I could have alternatively made a cutom preview controller, but the issue is I will have to make my custom controller handle previewing other document types such PDFs as well. That is why QLPrevireControlller was the ideal fit.

Am I missing something here. Please help.

Replies

I also am doing the same thing and had the same issue in iOS 10. What I noticed, was that if you sent the app to the background and then brought it the foreground the QLPreviewController would display the document. This obvioulsy is not the way it should work, but it made me think it simply needed to be refreshed. Therefore, on the ViewDidLoad method of the parent controller, I call the QLPreviewController's ViewWillAppear method and it now shows correctly.


Not sure if this is the best way to go about fixing it, but it worked for me.

I also had the same issue in iOS 10.

My solution is add this code [self addChildViewController:youtQLPreviewController];

And it works.

In case others (or future me) come here later; using [self addChildViewController:] does _not_ work for iOS 11.

I Use this code in viewDidLoad, then worked

addChild(self.previewController)

self.previewController.view.frame = self.view.bounds

self.previewController.didMove(toParent: self)