IOS 关于取消延迟执行函数的种种。performSelector与cancelPreviousPerformRequestsWithTarget
print?<PRE class=plain name="code">@inte易做图ce 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]
@inte易做图ce 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 @inte易做图ce 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]];//不
补充:移动开发 , IOS ,