[CPP]View Plain copy @interface NSObject (nsdelayedperforming)-(void) Performselector: (SEL) Aselector withobject: (ID) anarg Ument Afterdelay: (nstimeinterval) Delay inmodes: (Nsarray *) modes; -(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) delay; + (void) Cancelpreviousperformrequestswithtarget: (ID) atarget selector: (SEL) Aselector object: (ID) anargument; + (void) Cancelpreviousperformrequestswithtarget: (ID) atarget; @end
Recently see everyone on Cancelpreviousperformrequestswithtarget can't cancel with parameter
-(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) delay;
Situation, wrote a little bit of code debugging a bit, found that if it is with parameters, the cancellation of the parameters should also be consistent, otherwise you can not cancel the success.
Start deferred execution:
[CPP]View plain copy [self performselector: @selector (didrunincurrmodel:) Withobject:[nsnumber Numberwithbool:yes] AFTERDELAY:3.0F]; [Self performselector: @selector (didrunincurrmodelnoargument) Withobject:nil afterdelay:3.0f];
If the following cancellation method is performed within three seconds, the result is:
[CPP]View plain copy [NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (Didrunincurrmodel:) object : [NSNumber numberwithbool:yes]];//can cancel the success. [NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (didrunincurrmodel:) object:[nsnumber numberwithbool:no]];//cannot cancel the success. Parameter mismatch [nsobject cancelpreviousperformrequestswithtarget:self selector: @selector (didrunincurrmodel:) object:nil];// Success cannot be canceled. Parameter mismatch [nsobject cancelpreviousperformrequestswithtarget:self selector: @selector (didrunincurrmodelnoargument) object:nil];//can successfully cancel [NSObject cancelpreviousperformrequestswithtarget:self];//can successfully cancel all. [[Self class] cancelpreviousperformrequestswithtarget:self];//can successfully cancel all.
Code Download Address: http://download.csdn.net/detail/samuelltk/5481327