For IOS, you can cancel the function execution delay. PerformSelector and cancelPreviousPerformReque

Source: Internet
Author: User

Print? <PRE class = plain name = "code"> @ interface NSObject (NSDelayedPerforming)
 
-(Void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( NSTimeInterval) delay inModes :( NSArray *) modes;
-(Void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( NSTimeInterval) delay;
+ (Void) cancelPreviousPerformRequestsWithTarget :( id) aTarget selector :( SEL) aSelector object :( id) anArgument;
+ (Void) cancelPreviousPerformRequestsWithTarget :( id) aTarget;
 
@ End </PRE> <BR>
<BR>
<PRE> </PRE>
<PRE class = cpp name = "code"> </PRE> <PRE class = cpp name = "code" sizcache = "1" sizset = "5"> cancelPreviousPerformRequestsWithTarget cannot cancel <PRE class = cpp name = "code">-(void) with Parameters) when mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( NSTimeInterval) delay; </PRE>, I wrote a bit of code to debug it and found that if there is a parameter, the cancellation parameters must be the same; otherwise, the cancellation cannot be successful.
<PRE> </PRE>
<PRE class = cpp name = "code"> </PRE> <PRE class = cpp name = "code"> Start delayed execution: </PRE> <PRE class = cpp name = "code"> [self defined mselector: @ selector (didRuninCurrModel :) withObject: [NSNumber numberWithBool: YES] afterDelay: 3.0f];

[Self defined mselector: @ selector (didRuninCurrModelNoArgument) withObject: nil afterDelay: 3.0f]; </PRE>
<P> <BR>
</P>
<P> If the following cancellation method is executed within three seconds, the result is: </P>
<P> </P>
<PRE class = cpp name = "code"> [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: [NSNumber numberWithBool: YES]; // YES.

[NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: [NSNumber numberWithBool: NO]; // you cannot cancel the operation. Parameter Mismatch

[NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: nil]; // The task cannot be canceled successfully. Parameter Mismatch

[NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModelNoArgument) object: nil]; // cancel

[NSObject cancelPreviousPerformRequestsWithTarget: self]; // you can successfully cancel all tasks.
[[Self class] cancelPreviousPerformRequestsWithTarget: self]; // you can successfully cancel all tasks. </PRE>
<P> </P>
<P> <BR>
</P>
<P> <BR>
</P>
<BR>
<BR>
<P> <BR>
</P>
<PRE> </PRE>
<PRE> </PRE>
 
</PRE>

[Plain]
@ Interface NSObject (callback)-(void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( partial) delay inModes :( NSArray *) modes;-(void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( NSTimeInterval) delay; + (void) identifier :( id) aTarget selector :( SEL) aSelector object :( id) anArgument; + (void) identifier :( id) aTarget; @ end @ interface NSObject (NSDelayedPerforming)

-(Void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( NSTimeInterval) delay inModes :( NSArray *) modes;
-(Void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( NSTimeInterval) delay;
+ (Void) cancelPreviousPerformRequestsWithTarget :( id) aTarget selector :( SEL) aSelector object :( id) anArgument;
+ (Void) cancelPreviousPerformRequestsWithTarget :( id) aTarget;

@ End


[Cpp]
[Cpp]
Recently, we have seen that the callback parameter <PRE class = cpp name = "code">-(void) callback mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( NSTimeInterval) cannot be canceled) delay; </PRE>: A bit of code has been written for debugging. If a parameter is included, the parameters for cancellation must be consistent. Otherwise, the cancellation cannot be successful. <PRE> </PRE> <PRE class = cpp name = "code"> </PRE> <PRE class = cpp name = "code"> Start delayed execution: </PRE> <PRE class = cpp name = "code"> [self defined mselector: @ selector (didRuninCurrModel :) withObject: [NSNumber numberWithBool: YES] afterDelay: 3.0f]; [self defined mselector: @ selector (didRuninCurrModelNoArgument) withObject: nil afterDelay: 3.0f]; </PRE> <P> <BR> </P> <P> If the following cancellation method is executed within three seconds, the result is: </P> <PRE class = cpp name = "code"> [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: [NSNumber numberWithBool: YES]; // you can cancel the operation. [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: [NSNumber numberWithBool: NO]; // you cannot cancel the operation. The parameter does not match [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: nil]; // cannot be canceled successfully. The parameter does not match [NSObject failed: self selector: @ selector (didRuninCurrModelNoArgument) object: nil]; // you can successfully cancel [NSObject failed: self]; // you can successfully cancel all tasks. [[Self class] cancelPreviousPerformRequestsWithTarget: self]; // you can successfully cancel all tasks. </PRE> <P> </P> <BR> <P> <BR> </P> <PRE> </PRE> recently, we have seen that cancelPreviousPerformRequestsWithTarget cannot cancel [cpp] view plaincopyprint with parameters? -(Void) specify mselector :( SEL) aSelector withObject :( id) anArgument provided :( partial) delay;-(void) specify mselector :( SEL) aSelector withObject :( id) anArgument afterDelay :( partial) delay; in this case, I wrote a bit of code and debugged it. I found that if a parameter is included, the parameters to be canceled must be the same; otherwise, the cancellation cannot be successful.


[Cpp]
[Cpp]
Start delayed execution:
[Cpp]
[Self defined mselector: @ selector (optional :) withObject: [NSNumber numberWithBool: YES] afterDelay: 3.0f]; [self defined mselector: @ selector (optional) withObject: nil afterDelay: 3.0f]; [self defined mselector: @ selector (didRuninCurrModel :) withObject: [NSNumber numberWithBool: YES] afterDelay: 3.0f];

[Self defined mselector: @ selector (didRuninCurrModelNoArgument) withObject: nil afterDelay: 3.0f];


If the following cancellation method is executed within three seconds, the result is:

[Cpp] [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: [NSNumber numberWithBool: YES]; // The cancellation is successful. [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: [NSNumber numberWithBool: NO]; // you cannot cancel the operation. The parameter does not match [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: nil]; // cannot be canceled successfully. The parameter does not match [NSObject failed: self selector: @ selector (didRuninCurrModelNoArgument) object: nil]; // you can successfully cancel [NSObject failed: self]; // you can successfully cancel all tasks. [[Self class] cancelPreviousPerformRequestsWithTarget: self]; // you can successfully cancel all tasks. [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: [NSNumber numberWithBool: YES]; // the task can be canceled successfully.

[NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: [NSNumber numberWithBool: NO]; // you cannot cancel the operation. Parameter Mismatch

[NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModel :) object: nil]; // The task cannot be canceled successfully. Parameter Mismatch

[NSObject cancelPreviousPerformRequestsWithTarget: self selector: @ selector (didRuninCurrModelNoArgument) object: nil]; // cancel

[NSObject cancelPreviousPerformRequestsWithTarget: self]; // you can successfully cancel all tasks.
[[Self class] cancelPreviousPerformRequestsWithTarget: self]; // you can successfully cancel all tasks.

 

 

 

 

 


 

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.