如何在Monotouch中绑定NSObject <EAAccessoryDe​​legate>?

我有以下的Obj-C .h,绑定的正确方法是什么?

@interface iSmart : NSObject<EAAccessoryDelegate>{ id<iSmartDelegate> delegate; } @property(nonatomic, assign) id<iSmartDelegate> delegate; -(id)init; @end __________________________________________________________________________________________ @class iSmart; @protocol iSmartDelegate <NSObject> -(void) iSmartDidConnect; -(void) iSmartDidDisconnect; -(void) cardStatusChanged:(unsigned char)status; @end __________________________________________________________________________________________ 

在这一刻,我有这个协议和接口:

 [BaseType (typeof(NSObject))] [Model] interface iSmartDelegate { [Export("iSmartDidConnect")] void iSmartDidConnect(); [Export("iSmartDidDisconnect")] void iSmartDidDisconnect(); [Export("cardStatusChanged:")] void CardStatusChanged(Byte status); } [BaseType (typeof (EAAccessoryDelegate), Delegates=new string [] { "WeakDelegate" }, Events=new Type [] { typeof (iSmartDelegate)})] interface iSmart { //@property(nonatomic, assign) id<iSmartDelegate> delegate; [Export("delegate"), NullAllowed] NSObject WeakDelegate { get; set; } [Wrap("WeakDelegate")] iSmartDelegate Delegate { get; set; } //-(id)init; [Export("init")] NSObject init(); } 

当我尝试在Xamarin Studio 错误BI0000中生成项目时出现此错误:意外错误 – 请在http://bugzilla.xamarin.com (BI0000)上提交错误报告,

谢谢

协议只在你的ApiDefinition中内联,所以你EAAccessoryDelegate在你的iSmart定义中声明EAAccessoryDelegate的几个方法:

 [BaseType (typeof(NSObject))] interface iSmart : EAAccessoryDelegate{ //bind the protocol here [Export ("accessoryDidDisconnect:")] void AccessoryDidDisconnect (EAAccessory accessory); } 

对于绑定委托,请看http://docs.xamarin.com/guides/ios/advanced_topics/api_design#Delegates

[UPDATE 2013-02-26]你的委托绑定看起来不错,除了应该编组为.NET byte的本地unsigned char ,因为.NET chartypes是2字节长以适合Unicode字符。

[UPDATE 2013-02-27]另外,正如你最近添加到你的问题,正确的方式来绑定一个构造函数是这样的(见http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective -c_libraries ):

 [Export ("init")] IntPtr Constructor ();