我正在尝试绑定一个库,我在.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
Type
MonoTouch.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 ();
}
答案 0 :(得分: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
}