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

3

13

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

Gyrfalcon answered 11/10, 2014 at 0:20 Comment(5)
This is probably a bug in Apple's code as I have seen this warning as well even in their sample code. Please file a bug!Hindbrain
Thank you. That could be really just a stupig bugGyrfalcon
I'm having a similar problem ..... have you filed a radar?Germane
No sorry. i think this is really just a bugGyrfalcon
Thomas Deniau Can you please provide me the apple code link if you have .Bourguiba
H
19

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!

Hanforrd answered 14/6, 2015 at 4:4 Comment(3)
If you pass a navigation controller, it will push your view into the navigation stack, else if will present it modally. I wanted to remove that warning from the console, but instead it ruined my application. I have my navigation bar hidden and it makes it appear, broke all my constraints and so on… It is definitely just a warning.Aphotic
@Aphotic - yeah, this is a side effect. It didn't brake my constraints but presented the view inside the navigation controller. This is not what I wanted, so I reverted it and just ignore the warning. However, some people will want the view to be presented within the navigation controller - hence the answer.Hanforrd
You can simply the code by using return self.navigationController ?? self.Frech
B
4

I was having this same problem, and it turned out to be an issue with the UINavigationController of my view. I addressed it by changing the documentInteractionControllerViewControllerForPreview method:

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return [self navigationController];
}
Brinkman answered 21/4, 2015 at 17:38 Comment(0)
R
1

I think it is because the variable documentInteractionController only lives in the scope of the openFile function. Once the function is executed, the variable is garbage-collected and hence it is impossible to register the end appearance transition.

You can try promote the local variable to become a class variable.

Ratable answered 11/10, 2014 at 1:0 Comment(3)
Thank you for your reply! I tried this, but i receive the same error. Could this a problem because i have a ContainerView in my MainViewController?Gyrfalcon
I changed now my NSNotification and call now the function to open my UIDocumentInteraction from my DetailViewController (inside my ContainerView) - but still get the same "Warning".Gyrfalcon
I concur, the warning still appears for me too. The UIDocumentInteractionController is a class variable as well.Sacramentalism

© 2022 - 2024 — McMap. All rights reserved.