Open Monotouch Document - UIDocumentInterationController

I want to open a document in my iphone application written in mono-point - that is, run the PDF file in the default PDF viewer.

Think I should use a UIDocumentInterationController?

Anyone have any ideas on this.

I put together the following on a viewcontroller (with a toolbar)

but it does not work :-( He does nothing !!

string s = string.Format("{0}",strFilePath);

NSUrl ns = NSUrl.FromFilename (s);   

UIDocumentInteractionController PreviewController =
   UIDocumentInteractionController.FromUrl(ns);
PreviewController.Delegate =  new UIDocumentInteractionControllerDelegateClass();
PreviewController.PresentOpenInMenu(btnOpen,true);

  public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate
                {
                     public UIViewController FileViewController = new UIViewController();
                    public UIDocumentInteractionControllerDelegateClass ()
                    {
                    }

                    public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
                    {
                        return FileViewController;    
                    }

                    public override UIView ViewForPreview (UIDocumentInteractionController controller)
                    {
                        return FileViewController.View;
                    }
                }
+5
source share
1 answer

The first thing I will try is to ensure, when you present the options menu, that it happens in the main thread:

InvokeOnMainThread(delegate{
    PreviewController.PresentOpenInMenu(btnOpen,true);
});

, , . , , , , , . , , :

PreviewController.Delegate = new UIDocumentInteractionControllerDelegateClass(this);

...
...

public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate
{
    UIViewController viewC;

    public UIDocumentInteractionControllerDelegateClass(UIViewController controller)
    {
        viewC = controller;
    }

    public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
    {
        return viewC;
    }

    public override UIView ViewForPreview (UIDocumentInteractionController controller)
    {
        return viewC.View;
    }

    public override RectangleF RectangleForPreview (UIDocumentInteractionController controller)
    {
        return viewC.View.Frame;
    }
}

. , , , UIBarButtonItem try:

PreviewController.PresentOpenInMenu(new RectangleF(320,320,0,500), this.View, true);

, !

+6

All Articles