我想通過我的應用程序打開一個* .epub文件,我不太明白如何使它與UIDocumentInteractionController類。我看過官方的IOS documentation和examples以及一些examples而不是the net,但我不明白這個類是如何工作的。這就是我要做的事,就是我實現什麼我不明白:如何使工作在MonoTouch中的UIDocumentInteractionController
我有一個UIButton一個UIView:
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using System.Drawing;
public class MyView : UIViewController
{
UIButton myBtn;
public MyView() :base()
{
View.Frame = new RectangleF(0,0,1024,768);
var myRect = new RectangleF(300,300,100,50);
myBtn = UIButton.FromType(UIButtonType.RoundedRect);
myBtn.Frame = myRect;
myBtn.TouchUpInside += delegate
{
var dic = UIDocumentInteractionController.FromUrl(new NSUrl("http://192.168.50.50:2020/myfile.epub"));
var dicDel = new UIDocumentInteractionControllerDelegate();
dic.Delegate = dicDel;
InvokeOnMainThread(delegate
{
var result = dic.PresentOpenInMenu(myRect, View, true);
//If I do this -> NullReferenceException because delegate is null (something about autorelease?? Don't know)
if(!result) dic.Delegate.DidDismissOpenInMenu(dic);
});
}
}
}
最奇怪的是,如果我調試和檢查「DIC」(不委託)在調用PresentOpenInMenu()方法之前它顯示菜單(返回true),但在做完它之後,應用程序在Main.cs上爆炸,因爲我不明白autorelease的事情。
我有點迷路。有人可以幫助我理解這個課程,我該如何使它正確工作?提前致謝。
編輯:順便說一句,我也用了* .txt文件,結果也一樣。
我剛試過你的例子,我得到的錯誤是: UIDocumentInteractionController:invalid scheme http。僅支持文件方案。 – slott