美文网首页
iOS中的定时任务

iOS中的定时任务

作者: RogerHXJ | 来源:发表于2016-02-28 21:20 被阅读1731次

    定时任务的三种实现方法

    • 方法1:performSelector
    // 1.5s后自动调用self的hideHUD方法
    [self performSelector:@selector(hideHUD) withObject:nil afterDelay:1.5];
    
    • 方法2:GCD
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 1.5s后自动执行这个block里面的代码
        self.hud.alpha = 0.0;
    });
    
    • 方法3:NSTimer
    // 1.5s后自动调用self的hideHUD方法
    [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(hideHUD) userInfo:nil repeats:NO];
    // repeats如果为YES,意味着每隔1.5s都会调用一次self的hidHUD方法
    

    以上转自MJ笔记

    相关文章

      网友评论

          本文标题:iOS中的定时任务

          本文链接:https://www.haomeiwen.com/subject/rocgkttx.html