绑定StickNFind for Xamarin无法编译

时间:2014-01-23 23:51:35

标签: xamarin.ios xamarin

我正在尝试为StickNFind制作绑定,以便在基于Xamarin的项目中使用。

有问题的类是LeDeviceManager,它继承CBCentralManagerDelegate,这是一个抽象类,而UpdateState(m)方法不是绑定的一部分。

这是这个类的Obj-C标题:

interface LeDeviceManager : NSObject <CBCentralManagerDelegate>

@property (nonatomic,strong) NSMutableArray *devList;
@property (nonatomic)        CBCentralManager *btmgr;
@property (nonatomic,strong) id <LeDeviceManagerDelegate> delegate;

- (id)      initWithSupportedDevices: (NSArray *) devCls delegate: (id <LeDeviceManagerDelegate>) del;
- (void)    startScan;
- (void)    stopScan;

@end

这是我提出的约束力,目标Sharpie的大力帮助:

    [Model, BaseType (typeof(CBCentralManagerDelegate))]
    public partial interface LeDeviceManager
    {
        [Export ("devList", ArgumentSemantic.Retain)]
        NSMutableArray DevList { get; set; }

        [Export ("btmgr")]
        CBCentralManager Btmgr { get; set; }

        [Export ("delegate", ArgumentSemantic.Retain)]
        LeDeviceManagerDelegate Delegate { get; set; }

        [Export ("initWithSupportedDevices:delegate:")]
        IntPtr Constructor (NSObject[] devCls, LeDeviceManagerDelegate del);

        [Export ("startScan")]
        void StartScan ();

        [Export ("stopScan")]
        void StopScan ();

        [Export ("UpdatedState")] 
        [New] // Added as suggested by another SO post, also tried [Abstract]
        void UpdatedState(CBCentralManager mgr);
    }

我收到此错误:  错误CS0533:StickNFind.LeDeviceManager.UpdatedState(MonoTouch.CoreBluetooth.CBCentralManager)' hides inherited abstract member MonoTouch.CoreBluetooth.CBCentralManagerDelegate.UpdatedState(MonoTouch.CoreBluetooth.CBCentralManager)'(CS0533)(SNF_Binding)

我该如何解决这个问题:

1 个答案:

答案 0 :(得分:1)

您好,可以尝试一下吗?

[Protocol] // Added Protocol attribute
[Model]
[BaseType (typeof(NSObject))] //Changed BaseType to NSObject
public partial interface LeDeviceManager : ICBCentralManagerDelegate
{
    [Export ("devList", ArgumentSemantic.Retain)]
    NSMutableArray DevList { get; set; }

    [Export ("btmgr")]
    CBCentralManager Btmgr { get; set; }

    [Export ("delegate", ArgumentSemantic.Retain)]
    LeDeviceManagerDelegate Delegate { get; set; }

    [Export ("initWithSupportedDevices:delegate:")]
    IntPtr Constructor (NSObject[] devCls, LeDeviceManagerDelegate del);

    [Export ("startScan")]
    void StartScan ();

    [Export ("stopScan")]
    void StopScan ();

    [Export ("updatedState")] [New] // Notice I changed UpdatedState to updatedState lowercase u
    void UpdatedState(CBCentralManager mgr);
}

我强烈建议您阅读this doc

的“绑定协议”部分