gpt4 book ai didi

xamarin.ios - 如何将具有值 [PSPDFAnnotationParser 类]/[MyCustomAnnotationParser 类] 的 NSDictionary() 转换为 MonoTouch?

转载 作者:行者123 更新时间:2023-12-04 05:27:30 25 4
gpt4 key购买 nike

从我正在使用的绑定(bind) API 的文档中:

overrideClassNames

Use this to use specific subclasses instead of the default PSPDF* classes. e.g. add an entry of [PSPDFAnnotationParser class] / [MyCustomAnnotationParser class] as key/value pair to use the custom subclass. (MyCustomAnnotationParser must be a subclass of PSPDFAnnotationParser) Throws an exception if the overriding class is not a subclass of the overridden class. Note: does not get serialized when saved to disk.

@property (nonatomic, strong) NSDictionary *overrideClassNames



这是我尝试过但不起作用的方法。显然不需要字符串,而是需要实际类型或其他东西。如何在 MonoTouch 中使用它?
var oClassDic = new NSMutableDictionary();
oClassDic.Add(new NSString("[PSPDFAnnotationParser class]"), new NSString("[PSPDFKitAnnotationParser class]"));
oDoc.OverrideClassNames = oClassDic;

我创建的 PSPDFKitAnnotationParser 是这样的:
[Register("PSPDFKitAnnotationParser")]
public class PSPDFKitAnnotationParser : PSPDFAnnotationParser
{
public PSPDFKitAnnotationParser () : base()
{
}

public PSPDFKitAnnotationParser (PSPDFDocumentProvider provider) : base(provider)
{
}

public PSPDFKitAnnotationParser (IntPtr handle) : base(handle)
{
}

public PSPDFKitAnnotationParser (NSObjectFlag t) : base(t)
{
}

public PSPDFKitAnnotationParser (NSCoder coder) : base(coder)
{
}

最佳答案

MonoTouch 自己的绑定(bind)一般隐藏 class 并将它们替换为 .NETy 越多的 System.Type .

然而 MonoTouch.ObjCRuntime.Class类型存在,也可以使用。如果 native 代码需要 class实例那么您应该能够执行以下操作:

var oClassDic = new NSMutableDictionary();
oClassDic.Add(new Class("PSPDFAnnotationParser"), new Class("PSPDFKitAnnotationParser"));
oDoc.OverrideClassNames = oClassDic;

您可能需要稍微调整一下,因为 Class实例不是 NSObject ,这是一个 NativeObject在 MonoTouch 中,因此您可能需要更深入一层并使用 Handle属性 ( IntPtr ) 在向字典添加值/键时。

关于xamarin.ios - 如何将具有值 [PSPDFAnnotationParser 类]/[MyCustomAnnotationParser 类] 的 NSDictionary() 转换为 MonoTouch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13025969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com