ios - 将 objective-c 协议(protocol)委托(delegate)作为参数传递

标签 ios objective-c paypal

当我将 objective-c 协议(protocol)作为参数传递时,然后使用该委托(delegate)来触发其方法之一时,该方法不会触发。

我正在使用来自 Paypal iOS SDK 的委托(delegate)定义如下:

@protocol PayPalPaymentDelegate <NSObject>
    - (void)payPalPaymentDidCancel:(PayPalPaymentViewController *)paymentViewController;
@end

我有一个实现协议(protocol)的 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返回结果的时候,没有触发委托(delegate):

// 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 则触发它

最佳答案

一旦您创建了 paymentViewController,您是否在某处保留了 paypalDelegatePayPalPaymentViewController 仅保留对委托(delegate)的弱引用,因此如果没有,它将在创建 PayPalPaymentViewController.

关于ios - 将 objective-c 协议(protocol)委托(delegate)作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30559820/

相关文章:

单个项目的 PayPal 自适应支付

iphone - 应用程序因警报而暂停 - 我可以阻止这种情况发生吗?

ios - 如何为流媒体执行硬件加速的 H.264 编码和解码?

ios - 在 ios-charts subview 上拖动时,uiscrollview 不会滚动

ios - 强制用户使用自定义 init 方法进行初始化

rest - PayPal REST API - 如何获取 API 凭据?

objective-c - 如何使用动画更改 NSTableColumn 宽度

ios - UICollectionViewCell 变为隐藏=YES

ios - 如何从网络服务加载数组?

php - 自动定期计费系统付费成员(member) Pro wordpress 插件