IOS 关于取消延迟执行函数的种种。performSelector与cancelPreviousPerformRequestsWithTarget
@interface nsobject (nsdelayedperformin...
print?<pre class=plain name="code">@interface nsobject (nsdelayedperforming)
- (void)performselector:(sel)aselector withobject:(id)anargument 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</pre><br>
<br>
<pre></pre>
<pre class=cpp name="code"></pre><pre class=cpp name="code" sizcache="1" sizset="5">最近看到大家对cancelpreviousperformrequestswithtarget不能取消带参数的<pre class=cpp name="code">- (void)performselector:(sel)aselector withobject:(id)anargument afterdelay:(nstimeinterval)delay;</pre>情况,写了一点点代码调试了一下,发现如果是带参数,那取消时的参数也要一致,否则不能取消成功。
<pre></pre>
<pre class=cpp name="code"></pre><pre class=cpp name="code">开始延迟执行:</pre><pre class=cpp name="code">[self performselector:@selector(didrunincurrmodel:) withobject:[nsnumber numberwithbool:yes] afterdelay:3.0f];
[self performselector:@selector(didrunincurrmodelnoargument) withobject:nil afterdelay:3.0f];</pre>
<p><br>
</p>
<p>假如在三秒内执行以下取消方法,则结果分别为:</p>
<p></p>
<pre class=cpp name="code"> [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:[nsnumber numberwithbool:yes]];//可以取消成功。
[nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:[nsnumber numberwithbool:no]];//不能取消成功。参数不匹配
[nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:nil];//不能取消成功。参数不匹配
[nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodelnoargument) object:nil];//可以成功取消
[nsobject cancelpreviousperformrequestswithtarget:self];//可以成功取消全部。
[[self class] cancelpreviousperformrequestswithtarget:self];//可以成功取消全部。</pre>
<p></p>
<p><br>
</p>
<p><br>
</p>
<br>
<br>
<p><br>
</p>
<pre></pre>
<pre></pre>
</pre>
[plain]
@interface nsobject (nsdelayedperforming) - (void)performselector:(sel)aselector withobject:(id)anargument 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 @interface nsobject (nsdelayedperforming)
- (void)performselector:(sel)aselector withobject:(id)anargument 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
[cpp]
[cpp]
最近看到大家对cancelpreviousperformrequestswithtarget不能取消带参数的<pre class=cpp name="code">- (void)performselector:(sel)aselector withobject:(id)anargument afterdelay:(nstimeinterval)delay;</pre>情况,写了一点点代码调试了一下,发现如果是带参数,那取消时的参数也要一致,否则不能取消成功。 <pre></pre> <pre class=cpp name="code"></pre><pre class=cpp name="code">开始延迟执行:</pre><pre class=cpp name="code">[self performselector:@selector(didrunincurrmodel:) withobject:[nsnumber numberwithbool:yes] afterdelay:3.0f]; [self performselector:@selector(didrunincurrmodelnoargument) withobject:nil afterdelay:3.0f];</pre> <p><br> </p> <p>假如在三秒内执行以下取消方法,则结果分别为:</p> <p></p> <pre class=cpp name="code"> [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:[nsnumber numberwithbool:yes]];//可以取消成功。 [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:[nsnumber numberwithbool:no]];//不能取消成功。参数不匹配 [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:nil];//不能取消成功。参数不匹配 [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodelnoargument) object:nil];//可以成功取消 [nsobject cancelpreviousperformrequestswithtarget:self];//可以成功取消全部。 [[self class] cancelpreviousperformrequestswithtarget:self];//可以成功取消全部。</pre> <p></p> <p><br> </p> <p><br> </p> <br> <br> <p><br> </p> <pre></pre> <pre></pre> 最近看到大家对cancelpreviousperformrequestswithtarget不能取消带参数的[cpp] view plaincopyprint?- (void)performselector:(sel)aselector withobject:(id)anargument afterdelay:(nstimeinterval)delay; - (void)performselector:(sel)aselector withobject:(id)anargument afterdelay:(nstimeinterval)delay;情况,写了一点点代码调试了一下,发现如果是带参数,那取消时的参数也要一致,否则不能取消成功。
[cpp]
[cpp]
开始延迟执行: 开始延迟执行:
[cpp]
[self performselector:@selector(didrunincurrmodel:) withobject:[nsnumber numberwithbool:yes] afterdelay:3.0f]; [self performselector:@selector(didrunincurrmodelnoargument) withobject:nil afterdelay:3.0f]; [self performselector:@selector(didrunincurrmodel:) withobject:[nsnumber numberwithbool:yes] afterdelay:3.0f];
[self performselector:@selector(didrunincurrmodelnoargument) withobject:nil afterdelay:3.0f];
假如在三秒内执行以下取消方法,则结果分别为:
[cpp] [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:[nsnumber numberwithbool:yes]];//可以取消成功。 [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:[nsnumber numberwithbool:no]];//不能取消成功。参数不匹配 [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:nil];//不能取消成功。参数不匹配 [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodelnoargument) object:nil];//可以成功取消 [nsobject cancelpreviousperformrequestswithtarget:self];//可以成功取消全部。 [[self class] cancelpreviousperformrequestswithtarget:self];//可以成功取消全部。 [nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:[nsnumber numberwithbool:yes]];//可以取消成功。
[nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:[nsnumber numberwithbool:no]];//不能取消成功。参数不匹配
[nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodel:) object:nil];//不能取消成功。参数不匹配
[nsobject cancelpreviousperformrequestswithtarget:self selector:@selector(didrunincurrmodelnoargument) object:nil];//可以成功取消
[nsobject cancelpreviousperformrequestswithtarget:self];//可以成功取消全部。
[[self class] cancelpreviousperformrequestswithtarget:self];//可以成功取消全部。
上一篇: python实现简易名片管理系统
下一篇: ios 双指捏合放大缩小图片的例子