Monotouch-QLPreviewController问题 [英] Monotouch - Issue with QLPreviewController
问题描述
我正在尝试使用QLPreviewController查看PDF文件并将其发送,但是预览PDF文档后操作按钮出现问题.
I am trying to use QLPreviewController to see a PDF file and send it, but I have an issue with the action button after previewing the PDF document.
当我按下操作按钮(在右上角)时,应用程序崩溃,我得到:未处理的托管异常:抛出了Objective-C异常.名称:NSInternalInconsistencyException原因:UIDocumentInteractionController:无效的方案(空).仅文件方案是支持.(MonoTouch.Foundation.MonoTouchException)"
When I press the action button (at the top right) app crashes and I get: "Unhandled managed exception: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: UIDocumentInteractionController: invalid scheme (null). Only the file scheme is supported. (MonoTouch.Foundation.MonoTouchException)"
我进行了一些研究,发现如果从Internet下载文件或文件类型不是"file://..........",则可能会发生此问题. 我的NSUrl采用这种格式,所以我不知道为什么会出现此错误.
I did some research and it seams that this issue may occur if you download a file from the internet or if the file type is not "file:// .......... ". My NSUrl is on that format so I dont know why I have this error.
有人有什么主意吗?
谢谢
这是我调用控制器的代码:
Here is my code to call the Controller:
QLPreviewController previewController= new QLPreviewController();
previewController.DataSource=new MyQLPreviewControllerDataSource();
this.PresentViewController(previewController,true, null);
这是我的数据源代码:
public class MyQLPreviewControllerDataSource : QLPreviewControllerDataSource { public override int PreviewItemCount (QLPreviewController controller) {
return 1;
}
public override QLPreviewItem GetPreviewItem (QLPreviewController controller, int index)
{
string fileName = @"example.pdf";
var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
var library = Path.Combine (documents,fileName);
NSUrl url = NSUrl.FromFilename (library);
return new QlItem ("Title", url);
}
}
这是我的商品代码:
public class QlItem : QLPreviewItem { string _title; Uri _uri;
public QlItem (string title, Uri uri)
{
this._title = title;
this._uri = uri;
}
public override string ItemTitle {
get { return _title; }
}
public override NSUrl ItemUrl {
get { return _uri; }
}
}
推荐答案
您的QlItem类将原始NSUrl投射到Uri中,然后再将其投射到NSUrl中,并且在此过程中会丢失某些内容.
Your QlItem class is casting the original NSUrl into a Uri before casting it back into a NSUrl and something is getting lost along the way.
它看起来应该更像:
public class QlItem : QLPreviewItem
{
string title;
NSUrl uri;
public QlItem(string title, NSUrl uri)
{
this.title = title;
this.uri = uri;
}
public override string ItemTitle {
get { return title; }
}
public override NSUrl ItemUrl {
get { return uri; }
}
}
这篇关于Monotouch-QLPreviewController问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!