我试图让它工作,但我一定在某处犯了一个错误。这是根据 C 标头的委托类(截取):
@protocol PaymentEngineMiddlewareDelegate <NSObject>
@required
/*!
@brief Delegate method for startTransaction.
@param transResponse - Contains all the transaction response info from the gateway
*/
-(void)transactionComplete :(PaymentEngineTransactionResponse *)transResponse;
@optional
/*!
@brief Delegate method for device connected. The method gets called when the device is connected
*/
-(void)deviceConnected;
/*!
@brief Delegate method for device disconnected. The method gets called when the device is disconnected
*/
-(void)deviceDisconnected;
@end
为此,我有:
// @interface PaymentEngineMiddlewareDelegate : NSObject
[BaseType(typeof(NSObject))]
[Model]
[Protocol]
interface PaymentEngineMiddlewareDelegate
{
[Abstract]
[Export("transactionComplete:")]
void TransactionComplete(PaymentEngineTransactionResponse transResponse);
[Export("deviceConnected")]
void DeviceConnected();
[Export("deviceDisconnected")]
void DeviceDisconnected();
}
然后对于 PaymentEngineMiddleware 类,标头如下:
@interface PaymentEngineMiddleware : NSObject
+ (PaymentEngineMiddleware *) getInstance;
@property(nonatomic, strong) id<PaymentEngineMiddlewareDelegate> delegate;
//------------------------------Device Methods------------------------------
/*!
@brief This method must be called before starting any transaction. Use it to connect to a device.
@param deviceName The name of the device such as icmp or castle
@param setDelegate Sets to self
*/
-(void)setDevice :(NSString *)deviceName :(id)setDelegate;
@end
为此,我有:
// @interface PaymentEngineMiddleware : NSObject
[BaseType(typeof(NSObject))]
[Protocol]
interface PaymentEngineMiddleware
{
// +(id)getInstance;
[Static]
[Export("getInstance")]
PaymentEngineMiddleware GetInstance { get; }
[Export("delegate", ArgumentSemantic.Retain)]
PaymentEngineMiddlewareDelegate Delegate { get; set; }
[Export("setDevice:setDelegate:")]
void SetDevice(string deviceName, PaymentEngineMiddlewareDelegate setDelegate);
}
在代码中,当我尝试调用"中间件"时。SetDevice('name', this);" 这是一个从委托继承的类,我得到异常。
有什么明显的我错过或出错的地方吗?
setDevice
方法的选择器是错误的。
-(void)setDevice :(NSString *)deviceName :(id)setDelegate
方法的正确选择器是 setDevice::
。这是因为此方法中的第二个参数没有外部名称。
绑定的最终条目应如下所示
[Export("setDevice::")]
void SetDevice(string deviceName, PaymentEngineMiddlewareDelegate setDelegate);
您可以在Apple文档中阅读有关Objective-C中方法签名如何构造的更多信息。
还要在情节提要文件中查找代码中未实现的属性中的组件操作。
就我而言,我已经为故事板文件中的按钮提供了 Touch insideUp 操作,但没有在代码中实现。 实施后,此问题已不复存在。