• IOS 关于取消延迟执行函数的种种。performSelector与cancelPreviousPerformRequestsWithTarget


    http://blog.csdn.net/samuelltk/article/details/8994313

     

    [置顶] IOS 关于取消延迟执行函数的种种。performSelector与cancelPreviousPerformRequestsWithTarget

    分类: IOS
    1. @interface NSObject (NSDelayedPerforming)  
    2.   
    3. - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay inModes:(NSArray *)modes;  
    4. - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;  
    5. + (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anArgument;  
    6. + (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget;  
    7.   
    8. @end  

    最近看到大家对cancelPreviousPerformRequestsWithTarget不能取消带参数的
    - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;
    情况,写了一点点代码调试了一下,发现如果是带参数,那取消时的参数也要一致,否则不能取消成功。
    开始延迟执行:

    1. [self performSelector:@selector(didRuninCurrModel:) withObject:[NSNumber numberWithBool:YES] afterDelay:3.0f];  
    2.   
    3. [self performSelector:@selector(didRuninCurrModelNoArgument) withObject:nil afterDelay:3.0f];  

    假如在三秒内执行以下取消方法,则结果分别为:
    1. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:YES]];//可以取消成功。  
    2.   
    3. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:[NSNumber numberWithBool:NO]];//不能取消成功。参数不匹配  
    4.   
    5. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModel:) object:nil];//不能取消成功。参数不匹配  
    6.   
    7. [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRuninCurrModelNoArgument) object:nil];//可以成功取消  
    8.   
    9. [NSObject cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。  
    10. [[self class] cancelPreviousPerformRequestsWithTarget:self];//可以成功取消全部。  

    代码下载地址:http://download.csdn.net/detail/samuelltk/5481327
  • 相关阅读:
    批量转外部样式为行内样式
    AngularJS 笔记2
    windows特殊文件或文件夹
    zepto 入门
    js闭包
    AngularJS 笔记1
    sublime配置 sublimecondeintel 分号后不要提示
    sublime插件开发手记
    用flvplayer.swf在网页中播放视频(网页中flash视频播放的实现)
    无插件启动谷歌浏览器
  • 原文地址:https://www.cnblogs.com/itlover2013/p/4599046.html
Copyright © 2020-2023  润新知