Search code examples
iosipadswiftuidocumentinteractionquicklook

Warning: Unbalanced calls to begin/end appearance transitions for QLRemotePreviewContentController


I already found some solutions for this problem (it is caused because there is still an active animation).

But i am unable to solve that in my app when using a UIDocumentInteractionController on an iPad Application.

My ViewController looks like

MainViewController -> ContainerView

In this ContainerView i have a Sidebar, and from this SideBar i would like to open an UIDocumentInteractionController.

I use a NSNotification, because this "MainViewController" should handle multiple Files from different Views.

So: (this is in my MainViewController)

func openFile(notification: NSNotification){

    fileUrl = notification.object as NSURL

    var documentInteractionController = UIDocumentInteractionController(URL: self.fileUrl!)
    documentInteractionController.delegate = self

    documentInteractionController.presentPreviewAnimated(false)
}

func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) -> UIViewController {
    return self
}

But ill always get the following error:

Warning: Unbalanced calls to begin/end appearance transitions for QLRemotePreviewContentController

I dont know why? There should be no animation, and if i open another (modal) window there is no Warning here.

If i use a delay (for example for 5 Seconds!) there is stil this Warning.

Edit: Found out that i could be a Problem with my ContainerView. When i include "ViewWillDissapear" and "ViewDidDisappear" ill get the error here:

view will dissappear

Unbalanced calls to begin/end appearance transitions for <QLRemotePreviewContentController: 0x7d35d400>

viww Did dissapaer

Any Ideas? Thanks in advance


Solution

  • Your application must be using a navigation controller. If that's the case, navigation controller must be the one to handle interaction for the preview, not the view controller within it.

    Replacing your return self inside of documentInteractionControllerViewControllerForPreview with self.navigationController should solve the problem. However, you need to safely unwrap navigationController. See the complete method below:

    func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) -> UIViewController {
        if let navigationController = self.navigationController {
            return navigationController
        } else {
            return self
        }
    }
    

    Cudos to @staxim for the Objective-C solution!