简体   繁体   中英

Black screen when exiting PDF of UIDocumentInteractionController in iOS 7

I am using Xamarin monotouch c# for an iphone app showing PDF documents.

My problem is that I get a black screen when exiting a PDF in the UIDocumentInteractionController after i upgraded to iOS 7.

In the source constructor I make a new DocController:

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

When I select a row I get the PDF and show it (working):

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
}

This is my DocControllerDelegate class presenting the preview in my workspace:

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();
    }
}

The DidEnd action is not significant since the black screen is already there when the action triggers.

And yes I have set a root controller:

this.MainWindow.RootViewController = this.MainViewController;

I don't know if the warning was there in iOS6 but i could come back from my PDF just fine and select another one in my table to show and now in iOS7 I get a black screen when clicking on Done in the PDF.

How can I get back to my controller without a black screen and what changes in iOS7 affected this behaviour?

Thank you

EDIT

I have managed to get rid of the warning Presenting view controllers on detached view controllers is discouraged on Workspace with this:

this.MainViewController.AddChildViewController(this.Workspace); 

but I still get to the black screen on dismissing the PDF.

This is what I call in my UIDocumentInteractionControllerDelegate:

It will close that Document Preview window and allow you back to your previous view controller.

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

Try modding your Document Interaction Controller Delegate code to this :

public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
{

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM