IOS about canceling deferred execution functions. Performselector and Cancelpreviousperformrequestswithtarget

Source: Internet
Author: User

This article is not written by me[CPP]View Plaincopy
    1. @interface NSObject (nsdelayedperforming)
    2. -(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) delay Inmodes: (  Nsarray *) modes;
    3. -(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) delay;
    4. + (void) Cancelpreviousperformrequestswithtarget: (ID) atarget selector: (SEL) Aselector object: (ID) anargument;
    5. + (void) Cancelpreviousperformrequestswithtarget: (ID) atarget;
    6. @end

Recently saw everyone on the cancelpreviousperformrequestswithtarget can not be canceled with parameters
-(void) Performselector: (SEL) Aselector withobject: (ID) anargument afterdelay: (nstimeinterval) delay;
Situation, wrote a little bit of code debugging, and found that if it is with parameters, then cancel the parameters should be consistent, otherwise it can not be canceled successfully.
Start deferred execution:

[CPP]View Plaincopy < param name= "wmode" value= "Transparent" >
    1. [Self performselector: @selector (didrunincurrmodel:) withobject:[nsnumber Numberwithbool:yes] afterdelay:3.0f];
    2. [Self performselector: @selector (didrunincurrmodelnoargument) Withobject:nil afterdelay:3.0f];

If the following cancellation methods are executed within three seconds, the results are:

[CPP]View Plaincopy
  1. [NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (didrunincurrmodel:) object:[nsnumber Numberwithbool:yes]];  //Can be canceled successfully.
  2. [NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (didrunincurrmodel:) object:[nsnumber Numberwithbool:no]]; //cannot be canceled successfully. Parameters do not match
  3. [NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (Didrunincurrmodel:) Object:nil]; //cannot be canceled successfully. Parameters do not match
  4. [NSObject cancelpreviousperformrequestswithtarget:self selector: @selector (didrunincurrmodelnoargument) Object:nil ]; //Can be cancelled successfully
  5. [NSObject cancelpreviousperformrequestswithtarget:self];  //Can cancel all successfully.
  6. [Self class] cancelpreviousperformrequestswithtarget:self];  //Can cancel all successfully.

Code: http://download.csdn.net/detail/samuelltk/5481327

IOS about canceling deferred execution functions. Performselector and Cancelpreviousperformrequestswithtarget

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.