Monotouch打开文档 - UIDocumentInterationController [英] Monotouch open document - UIDocumentInterationController

查看:108
本文介绍了Monotouch打开文档 - UIDocumentInterationController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的iphone应用程序中用单声道打开一个文档
- 即在默认的PDF查看器中启动一个PDF文件。

I want to open a document on my iphone app written in monotouch - i.e. launch a PDF file in the default PDF viewer.

应该使用UIDocumentInterationController?

I think I should be using UIDocumentInterationController?

任何人都有任何想法。

a viewcontroller(with a toolbar)

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

但它不工作:-(它什么也不做!)

but it doesnt work :-( It 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;
                    }
                }


推荐答案

我会尝试,确保当你提出的选项菜单,它正在发生在主线程:

First thing I would try, is ensuring when you present the options menu, that it is taking place on the main thread:

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

如果单独不工作,我注意到的另一件事是,控制器在委托类中。它似乎没有添加到堆栈在你的代码中的任何地方,所以也许这就是为什么它不显示。我使用的代码如下:

If that alone doesn't work, another thing I noticed is that you're creating a new view controller in the delegate class. It doesn't appear to be added to the stack anywhere in your code, so maybe thats why it's not showing. Code I've used is as follows:

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 尝试:

This will then use the current viewcontroller to present the preview in. The only other change I can think of using is rather than presenting from a UIBarButtonItem try:

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

我希望这有助于!

这篇关于Monotouch打开文档 - UIDocumentInterationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆