警告:QLRemotePreviewContentController的开始/结束外观转换调用不平衡

13

我已经为这个问题找到了一些解决方案(它是由于仍然有一个活动的动画而引起的)。

但是,在iPad应用程序中使用UIDocumentInteractionController时,我无法解决我的应用程序中的该问题。

我的ViewController看起来像

MainViewController -> ContainerView

在这个ContainerView中,我有一个侧边栏,我想从这个侧边栏打开一个UIDocumentInteractionController。

我使用NSNotification,因为这个“MainViewController”应该处理来自不同视图的多个文件。

所以:(这是在我的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
}

但我总是遇到以下错误:

警告:QLRemotePreviewContentController的开始/结束外观转换调用不平衡

我不知道为什么?应该没有动画,如果我打开另一个(模态)窗口,这里就没有警告。

如果我使用延迟(例如5秒!),仍然会出现此警告。

编辑:发现可能是我的ContainerView出了问题。当我包括“ViewWillDissapear”和“ViewDidDisappear”时,就会在这里出现错误:

view will dissappear

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

viww Did dissapaer

有什么想法吗?提前感谢。


这很可能是苹果代码中的一个错误,因为我甚至在他们的示例代码中也看到了这个警告。请提交一个错误报告! - Thomas Deniau
谢谢。那可能只是一个愚蠢的错误。 - derdida
我遇到了类似的问题......你是否已经提交了雷达报告? - Aaron
不,抱歉。我认为这只是一个错误。 - derdida
Thomas Deniau,如果您有的话,能否提供给我苹果代码链接? - Lakshmi Reddy
3个回答

19

您的应用程序必须使用导航控制器。如果是这种情况,导航控制器必须处理预览的交互,而不是其中的视图控制器。

documentInteractionControllerViewControllerForPreview 中的 return self 替换为 self.navigationController 应该可以解决问题。但是,您需要安全地取消包装 navigationController。请参见以下完整方法:

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

感谢 @staxim 提供的 Objective-C 解决方案!


3
如果你传递了一个导航控制器,它将把你的视图推入导航堆栈中,否则它将以模态方式呈现。我想从控制台中删除那个警告,但结果却毁了我的应用程序。我隐藏了我的导航栏,但它让它出现了,破坏了所有我的约束等等... 这绝对只是一个警告。 - Crazyrems
@Crazyrems - 是的,这是一个副作用。它没有破坏我的约束条件,但在导航控制器中呈现了视图。这不是我想要的,所以我还原了它并忽略了警告。然而,有些人会希望将视图呈现在导航控制器内 - 这就是答案。 - Ilya Vinogradov
你可以使用 return self.navigationController ?? self 来简化代码。 - Frederik Winkelsdorf

4

我曾经遇到过同样的问题,最后发现是我的视图中的UINavigationController出了问题。我通过更改documentInteractionControllerViewControllerForPreview方法来解决它:

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return [self navigationController];
}

1
我认为这是因为变量documentInteractionController只存在于openFile函数的范围内。一旦函数执行完毕,该变量就会被垃圾回收,因此无法注册结束外观转换。
您可以尝试将局部变量提升为类变量。

1
谢谢您的回复!我尝试了这个方法,但是我收到了相同的错误。这可能是因为我在我的MainViewController中有一个ContainerView引起的问题吗? - derdida
我现在更改了我的NSNotification,并从我的DetailViewController(位于我的ContainerView内部)调用打开UIDocumentInteraction的函数 - 但仍然收到相同的“警告”。 - derdida
1
我同意,我也看到了警告。UIDocumentInteractionController也是一个类变量。 - Gerald Eersteling

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接