1

MonoTouch 開発は初めてで、アプリに PDF 表示機能を埋め込みたいと考えています。それを行うためのいくつかのリソースを見つけましたが、安定して高速にするためのすべての追加実装についての十分なコメントも見ています。

多くの機能 (CATiledLayer、マルチスレッド、ページ スクロール、サムネイル、デバイスの回転など) を既に実装している優れた ObjectiveC ライブラリがあることがわかりました: https://github.com/vfr/Reader

最近、monotoch バインディングのドキュメントを読んだ後、これを MonoTouch でバインドしようとしましたが、成功しませんでした。これをライブラリ (.a) ファイルにエクスポートでき、バインディング API を作成しました。

    //@interface ReaderDocument : NSObject <NSObject, NSCoding>
    [BaseType (typeof (NSObject))]
    interface ReaderDocument {

    //- (id)initWithFilePath:(NSString *)fullFilePath password:(NSString *)phrase;
    [Export("initWithFilePath:password")]
    IntPtr Constructor (string path, string phrase);

    //Properties
    [Export("guid")]
    string Guid { get;}

    [Export("fileDate")]
    NSDate FileDate { get;}

    [Export("lastOpen")]
    NSDate LastOpen { get;set;}

    [Export("fileSize")]
    NSNumber FileSize{ get;}

    [Export("pageCount")]
    NSNumber PageCount { get;}

    [Export("pageNumber")]
    NSNumber PageNumber { get;set;}

    [Export("bookmarks")]
    NSMutableIndexSet Bookmarks { get;}

    [Export("fileName")]
    string FileName { get;}

    [Export("password")]
    string Password { get;}

    [Export("fileURL")]
    NSUrl FileURL { get;}

    //Methods

    //+ (ReaderDocument *)withDocumentFilePath:(NSString *)filename password:(NSString *)phrase;
    [Static, Export("withDocumentFilePath:password")]
    ReaderDocument WithDocumentFilePath(string filename, string phrase);

    //+ (ReaderDocument *)unarchiveFromFileName:(NSString *)filename password:(NSString *)phrase;
    [Static, Export("unarchiveFromFileName:password")]
    ReaderDocument UnarchiveFromFileName(string filename, string phrase);

    //- (void)saveReaderDocument;
    [Export("saveReaderDocument")]
    void SaveReaderDocument();

    //- (void)updateProperties;
    [Export("updateProperties")]
    void updateProperties();
}

私は次の行について非常に確信が持てません。

//@interface ReaderDocument : NSObject <NSObject, NSCoding>
    [BaseType (typeof (NSObject))]
    interface ReaderDocument

「」で何かをしなければならないかどうかわかりませんか?

MonoTouch で次のコードを作成できるようになりました

ReaderDocument doc =  ReaderDocument.withDocumentFilePath("Tamarin.pdf","");

また

ReaderDocument doc = new ReaderDocument("Tamarin.pdf","yrt");

どちらも「認識されないセレクター」エラーが発生します

  2012-11-04 22:15:05.731 PFDTest1[4149:1507] +[ReaderDocument withDocumentFilePath:password]: unrecognized selector sent to class 0x2f7738

[ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.Foundation.MonoTouchException: Objective-C     exception thrown.  Name: NSInvalidArgumentException Reason: +[ReaderDocument   withDocumentFilePath:password]: unrecognized selector sent to class 0x2f7738
at (wrapper managed-to-native)   MonoTouch.ObjCRuntime.Messaging:IntPtr_objc_msgSend_IntPtr_IntPtr   (intptr,intptr,intptr,intptr)
at VFRBinding4.ReaderDocument.withDocumentFilePath (System.String filename,  System.String phrase) [0x00000] in <filename unknown>:0 
at PFDTest1.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00030] in /Users/matthiasvalcke/Projects/PFDTest1/PFDTest1/AppDelegate.cs:39 
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
at PFDTest1.Application.Main (System.String[] args) [0x00000] in  /Users/matthiasvalcke/Projects/PFDTest1/PFDTest1/Main.cs:17 

何か案は?

4

2 に答える 2

1

私は完全に間違っている可能性がありますが、セレクターが間違っていると思います:

たとえば、「withDocumentFilePath:password」は「withDocumentFilePath:password:」にする必要があります。

于 2012-11-05T13:49:04.977 に答える
1

他にも問題がある可能性がありますが、バインディングがコンストラクタに対して間違っています。

//- (id)initWithFilePath:(NSString *)fullFilePath password:(NSString *)phrase;
[Export("initWithFilePath:password")]
void InitWithFilePath(string path, string password);

ObjectiveCinit*セレクターは、C# コンストラクターとしてバインドする必要があります。例えば

[Export("initWithFilePath:password")]
IntPtr Constructor (string path, string password);

そして、それはあなたがインスタンスを作成するために使用するものでなければなりません、例えば

ReaderDocument doc = new ReaderDocument ("sample.pdf", "");
// ...
于 2012-11-04T16:27:57.150 に答える