2012-11-04 45 views
1

我是MonoTouch開發的新手,我想在我的應用程序中嵌入一些PDF查看功能。我已經找到了幾個資源來做這件事,但是,我還看到有關所有其他實現的足夠的評論,以使其穩定和快速。綁定到Objective C庫(VFR閱讀器)

我現在看到有哪些已經實現了很多功能了良好的ObjectiveC庫(CATiledLayer,多線程,頁面滾動,拇指指甲,設備旋轉...):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(); 
} 

我對下面的行BTW非常不確定:

//@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 

任何想法?

+0

嘿@Matt,您是否成功創建了vfr-reader的綁定?我有一個類似的問題,一點幫助會非常棒! – chritaso

回答

1

有可能是其他問題,但您的綁定是錯誤的構造,即

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

的ObjectiveC init*選擇應該綁定爲C#構造函數。例如。

​​

這應該是你用來創建實例的東西,例如,

ReaderDocument doc = new ReaderDocument ("sample.pdf", ""); 
// ... 
+0

感謝poupou。我研究了這一點,我確實必須將其配置爲構造函數。我還發現如何編輯項目,而我沒有收到項目跟蹤(「無法識別的選擇器」)。 PS:我更新了我的起始帖子。我不知道是否編輯開始帖子是不鼓勵在stackoverflow上 – Matt

+0

'[Static,Export(「withDocumentFilePath:password」)]'應該是'[Static,Export(「withDocumentFilePath:password:」)]',即在選擇器名稱末尾缺少冒號(其他選擇器可能有相同的錯誤,包括用於.ctor的那個) – poupou

+0

感謝poupou&jstedfast。在更改構造函數並在末尾添加冒號後,現在可以使用綁定到這個類。 – Matt

1

我可能是完全錯誤的,但我覺得你的選擇是錯誤的:

例如「withDocumentFilePath:password」應該是「withDocumentFilePath:password:」