Top IOS about canceling deferred execution functions. Performselector and Cancelpreviousperformrequestswithtarget

Source: Internet
Author: User
[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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.