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

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

问题描述

我想在我的 iphone 应用程序上打开一个用单点触控编写的文档- 即在默认 PDF 查看器中启动 PDF 文件.

我认为我应该使用 UIDocumentInterationController 吗?

任何人对此有任何想法..

我已将以下内容放在一个视图控制器(带工具栏)上

但它不起作用:-(它什么也不做!!

<块引用>

string s = string.Format("{0}",strFilePath);NSUrl ns = NSUrl.FromFilename(s);UIDocumentInteractionController PreviewController =UIDocumentInteractionController.FromUrl(ns);PreviewController.Delegate = new UIDocumentInteractionControllerDelegateClass();PreviewController.PresentOpenInMenu(btnOpen,true);

<小时>

 公共类 UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate{public UIViewController FileViewController = new UIViewController();公共 UIDocumentInteractionControllerDelegateClass (){}公共覆盖 UIViewController ViewControllerForPreview(UIDocumentInteractionController 控制器){返回 FileViewController;}公共覆盖 UIView ViewForPreview(UIDocumentInteractionController 控制器){返回 FileViewController.View;}}

解决方案

我要尝试的第一件事是确保当您呈现选项菜单时,它发生在主线程上:

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

如果单独这样做不起作用,我注意到的另一件事是您正在委托类中创建一个新的视图控制器.它似乎没有被添加到代码中任何地方的堆栈中,所以也许这就是它没有显示的原因.我使用的代码如下:

PreviewController.Delegate = new UIDocumentInteractionControllerDelegateClass(this);......公共类 UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate{UIViewController viewC;公共 UIDocumentInteractionControllerDelegateClass(UIViewController 控制器){viewC = 控制器;}公共覆盖 UIViewController ViewControllerForPreview(UIDocumentInteractionController 控制器){返回视图C;}公共覆盖 UIView ViewForPreview(UIDocumentInteractionController 控制器){返回视图C.View;}公共覆盖 RectangleF RectangleForPreview(UIDocumentInteractionController 控制器){返回 viewC.View.Frame;}}

这将使用当前的视图控制器来呈现预览.我能想到的唯一其他改变是而不是从 UIBarButtonItem 尝试:

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

我希望这会有所帮助!

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

I think I should be using UIDocumentInterationController?

Anyone have any Ideas on this..

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

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

I hope this helps!

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

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