0

我正在尝试绑定一个库,并且在 .h 文件中有以下定义

@interface FbFAccessoryController : NSObject <EAAccessoryDelegate, NSStreamDelegate> {

    id <FbFmobileOneDelegate> _delegate;

    BOOL    ScannerStarted;
}

@property (nonatomic, assign) id <FbFmobileOneDelegate> delegate;

@property (readonly, nonatomic) BOOL Version1b;

- (BOOL)mobileOneConnected;

@property (readonly, nonatomic) NSNumber *VoltIndex;

@property (readonly, nonatomic) BOOL ScannerStarted;

- (void)startScanner;

- (void)stopScanner;

- (void)checkBattery;

@end

对于代表

@class FbFAccessoryController;

@protocol FbFmobileOneDelegate <NSObject>

@required

- (void) mobileOneAccessoryController:(FbFAccessoryController *)mobileOne didChangeConnectionStatus:(BOOL)connected;

- (void) mobileOneAccessoryController:(FbFAccessoryController *)mobileOne didReceiveData:(NSData *)data;

@optional

- (void) mobileOneAccessoryController:(FbFAccessoryController *)mobileOne didReceiveError:(NSError *)error;

- (void) mobileOneAccessoryController:(FbFAccessoryController *)mobileOne didReceiveScannerStartStop:(BOOL)started;

- (void) mobileOneAccessoryController:(FbFAccessoryController *)mobileOne didReceiveDataSpin:(BOOL)started;

@end

我使用 ObjectiveSharpie 生成绑定,但是当我尝试编译时出现以下错误:

在接口列表中键入MonoTouch.ExternalAccessory.EAAccessoryDelegate' in interface list is not an interface TypeMonoTouch.Foundation.NSStreamDelegate' 不是接口

Objectiveharpie 生成的代码是:

public partial interface FbFAccessoryController : EAAccessoryDelegate, NSStreamDelegate {


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

        [Static, Export ("sharedController")]
        FbFAccessoryController SharedController { get; }

        [Export ("Version1b")]
        bool Version1b { get; }

        [Export ("mobileOneConnected")]
        bool MobileOneConnected { get; }

        [Export ("VoltIndex")]
        NSNumber VoltIndex { get; }

        [Export ("ScannerStarted")]
        bool ScannerStarted { get; }

        [Export ("startScanner")]
        void StartScanner ();

        [Export ("stopScanner")]
        void StopScanner ();

        [Export ("checkBattery")]
        void CheckBattery ();
    }
4

1 回答 1

0

协议应该用[Model]属性修饰,所以你可以像接口一样实现它们。

因此,如果不使用 ObjectiveSharpie,它应该如下所示:

[BaseType (typeof(NSObject))]
interface FbFAccessoryController : EAAccessoryDelegate, NSStreamDelegate {

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

    // ... //
}

前提是代表的定义如下:

[Model] //Look, no BaseType
interface EAAccessoryDelegate {
    // [Export] what you need here
}

[Model]
interface NSStreamDelegate {
    // [Export] what you need here
}
于 2013-08-26T08:56:24.330 回答