1

我是 MonoTouch 开发的新手,我想在我的应用程序中嵌入一些 PDF 查看功能。我已经找到了一些资源来做到这一点,但是,我也看到了关于所有其他实现的足够多的评论,以使其稳定和快速。

我现在看到有一个很好的 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();
}

我非常不确定以下行顺便说一句:

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

可能还有其他问题,但构造函数的绑定是错误的,即

//- (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 回答
1

我可能完全错了,但我认为你的选择器是错误的:

例如“withDocumentFilePath:password”应该是“withDocumentFilePath:password:”

于 2012-11-05T13:49:04.977 回答