取消延时功能[通俗易懂]

2022-01-18 13:56:50 浏览数 (1)

大家好,又见面了,我是全栈君。

代码语言:javascript复制
- (void) networkReachabilityDidUpdate:(NetworkReachability*)reachability

{

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(reachabilityChanged) object:nil];

    

    [self performSelector:@selector(reachabilityChanged) withObject:nil afterDelay:0.1f];

}

//cancelPreviousPerformRequestsWithTarget终止最后performSelector的Delay转让

//上面的例子是防止afterDelay重复调用时间reachabilityChanged

0 人点赞