2
votes

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.

1
What is happening in "DidEndPreview", inside I'm assuming your "Workspace" class, that is a UITableViewController? Do you have a variable that would cause the Document Preview window to show at the wrong time on returning to your Workspace controller?Slack Shot
The DidEndPreview only shows back my table modal as a popover of my workspace controller which it does correctly only if I let my ViewControllerForPreview returning my AppDelegate.Instance.Workspace. I'm assuming the solution you proposed is only good for navControllers. I'm pretty sure something in iOS7 is bugged right now because even if my popover table modal shows up my xamarin freezes when I try to enable any breakpoint..pm.lemay
Yeah. Quite possible. What sucks about Stackoverflow, is that you don't get.. Reputation for trying. Heh.Slack Shot
I added a listener on my workspace's bounds and it becomes empty! went from {768,1024} to {0,0}. I set them back to the MainScreen bounds so I can finally see my workspace, but it's frozen and can't click anywhere..pm.lemay

1 Answers

1
votes

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