OGeek|极客世界-中国程序员成长平台

标题: c# - 在 iOS 7 中退出 UIDocumentInteractionController 的 PDF 时出现黑屏 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:12
标题: c# - 在 iOS 7 中退出 UIDocumentInteractionController 的 PDF 时出现黑屏

我正在将 Xamarin monotouch c# 用于显示 PDF 文档的 iphone 应用程序。

我的问题是升级到 iOS 7 后在 UIDocumentInteractionController 中退出 PDF 时出现黑屏。

在源构造函数中,我创建了一个新的 DocController:

this.DocumentPreview = new UIDocumentInteractionController();
this.DocumentPreview.Delegate = new DocumentInteractionDelegate(this.DidEndPreview);

当我选择一行时,我会得到 PDF 并显示它(工作):

public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
    // Get PDF url from indexpath
    ...
    // Set url
    this.DocumentPreview.Url = url;
    this.DocumentPreview.PresentPreview(true);
    // Here i get a warning : Presenting view controllers on detached view controllers is discouraged
}

这是我的 DocControllerDelegate 类,在我的工作区中显示预览:

public class DocumentInteractionDelegate : UIDocumentInteractionControllerDelegate
{
    private Action DidEnd;

    public DocumentInteractionDelegate(Action didEnd)
    {
        this.DidEnd = didEnd;
    }

    public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
    {
        return AppDelegate.Instance.Workspace;
    }

    public override void DidEndPreview(UIDocumentInteractionController controller)
    {
        this.DidEnd.Execute();
    }
}

DidEnd Action 并不重要,因为当 Action 触发时黑屏已经存在。

是的,我已经设置了一个根 Controller :

this.MainWindow.RootViewController = this.MainViewController;

我不知道 iOS6 中是否存在警告,但我可以很好地从我的 PDF 中返回并在我的表格中选择另一个要显示的内容,现在在 iOS7 中,单击 完成时出现黑屏 在 PDF 中。

如何在没有黑屏的情况下返回我的 Controller ?iOS7 中的哪些变化影响了这种行为?

谢谢

编辑

我已经设法摆脱了警告在工作区不鼓励在分离的 View Controller 上显示 View Controller :

this.MainViewController.AddChildViewController(this.Workspace); 

但我在关闭 PDF 时仍会出现黑屏。



Best Answer-推荐答案


这就是我在 UIDocumentInteractionControllerDelegate 中调用的内容:

它将关闭该文档预览窗口并允许您返回到之前的 View Controller 。

UIApplication.SharedApplication.Windows [0].RootViewController.DismissViewController (true,null);

尝试将您的文档交互 Controller 委托(delegate)代码修改为:

public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
{

    return UIApplication.SharedApplication.Windows[0].RootViewController;
}

关于c# - 在 iOS 7 中退出 UIDocumentInteractionController 的 PDF 时出现黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19146955/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4