ios - Passing an objective-c protocol delegate as a parameter -
when pass objective-c protocol parameter, when , delegate used trigger 1 of methods, method not fire.
i'm using delegate paypal ios sdk defined follows:
@protocol paypalpaymentdelegate <nsobject> - (void)paypalpaymentdidcancel:(paypalpaymentviewcontroller *)paymentviewcontroller; @end
i have uiviewcontroller implements protocol:
//simpleviewcontroller.h @interface simpleviewcontroller : uiviewcontroller<paypalpaymentdelegate>
and method signature following:
// helperfunctions.m + (void) dosomething: (id<paypalpaymentdelegate>)paypaldelegate { // selector 'paypalpaymentdidcancel' fire [paypaldelegate performselector:@selector(paypalpaymentdidcancel:) withobject:self] } // called simpleviewcontroller.m implements paypalpaymentdelegate [helperfunctions dosomething: self]
the problem when paypal returns result, not trigger delegate:
// code inside of 'success' block of afnetworking call paypalpaymentviewcontroller *paymentviewcontroller; paymentviewcontroller = [[paypalpaymentviewcontroller alloc] initwithpayment:payment configuration:paypalconfiguration delegate:paypaldelegate];
the paypaldelegate passed 'delegate' here never triggered paypal. whereas triggered if done simpleviewcontroller.m , not via method dosomething
once have created paymentviewcontroller
keeping hold of paypaldelegate
somewhere? paypalpaymentviewcontroller
keeps weak reference delegate if not being released (and therefore none of it's methods firing) arc @ end of scope creates paypalpaymentviewcontroller
.
Comments
Post a Comment