当我将一个Objective-C协议作为参数传递时,当并且该委托被用来触发其中一个方法时,该方法不会触发。
我正在使用从Paypal iOS SDK定义的委托。
问题在于当PayPal返回结果时,它不会触发委托。
在这里传递给“delegate”的paypalDelegate从未被PayPal触发。但是,如果通过simpleviewcontroller.m完成而不是通过doSomething方法完成,则会触发它。
我正在使用从Paypal iOS SDK定义的委托。
@protocol PayPalPaymentDelegate <NSObject>
- (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController;
@end
我有一个实现了协议的UIViewController:
//simpleviewcontroller.h
@interface SimpleViewController : UIViewController<PayPalPaymentDelegate>
并且具有以下方法签名:
// HelperFunctions.m
+ (void) doSomething: (id<PayPalPaymentDelegate>)paypalDelegate
{
// the selector 'payPalPaymentDidCancel' DOES fire
[paypalDelegate performSelector:@selector(payPalPaymentDidCancel:) withObject:self]
}
// called from simpleviewcontroller.m that implements PayPalPaymentDelegate
[HelperFunctions doSomething: self]
问题在于当PayPal返回结果时,它不会触发委托。
// code inside of the 'success' block of an AFNetworking call
PayPalPaymentViewController *paymentViewController;
paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment
configuration:paypalConfiguration
delegate:paypalDelegate];
在这里传递给“delegate”的paypalDelegate从未被PayPal触发。但是,如果通过simpleviewcontroller.m完成而不是通过doSomething方法完成,则会触发它。
[paypalDelegate performSelector:@selector(payPalPaymentDidCancel:) withObject:self];
的那一行,self
是指什么?毕竟它是在一个类方法中。 - Alex Basson