定时器

作者: Alan龙马 | 来源:发表于2018-07-14 23:23 被阅读4次
    #-----GCD
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
     });
    DispatchQueue.main.asyncAfter(deadline: .now()+0.4) {
     }
    
    @property (nonatomic,strong) NSTimer *timerReloadList;
    - (NSTimer *)timerReloadList
    {
        if (!_timerReloadList) {
            _timerReloadList = [NSTimer scheduledTimerWithTimeInterval:2
                                                                target:self
                                                              selector:@selector(updateDeviceListShow)
                                                              userInfo:nil
                                                               repeats:YES];
        }
        return _timerReloadList;
    }
    - (void)updateDeviceListShow{
        NSLog(@"xxxx");
    }
      [self.timerReloadList setFireDate:[NSDate distantPast]]; //开启
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        
        [self.timerReloadList invalidate];//释放
        self.timerReloadList = nil;
    }
    

    相关文章

      网友评论

          本文标题:定时器

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