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

derdida
  • 14,784
  • 16
  • 90
  • 139

3 Answers3

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!

Ilya Vinogradov
  • 746
  • 6
  • 7
  • 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. – Crazyrems Jul 08 '15 at 14:37
  • @Crazyrems - 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. – Ilya Vinogradov Oct 04 '16 at 16:28
  • You can simply the code by using `return self.navigationController ?? self`. – Frederik Winkelsdorf Jan 18 '17 at 19:43
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];
}
staxim
  • 1,328
  • 14
  • 15
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.

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
  • 1
    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? – derdida Oct 11 '14 at 01:04
  • 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". – derdida Oct 11 '14 at 01:10
  • 1
    I concur, the warning still appears for me too. The UIDocumentInteractionController is a class variable as well. – Gerald Eersteling Jan 29 '15 at 11:17