SimonGao

IOS 定时器

-(void)initTimer{
    
    //时间间隔
    NSTimeInterval timeInterval = 1.0 ;
    //定时器
    NSTimer   *showTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
                                                           target:self
                                                         selector:@selector(handleMaxShowTimer:)
                                                         userInfo:nil
                                                          repeats:NO];
    [showTimer fire];
}

//触发事件
-(void)handleMaxShowTimer:(NSTimer *)theTimer{
   
    NSLog(@"initTimer");
    
}

 

方式二:

    //时间间隔
    NSTimeInterval timeInterval = 1.0 ;
    //定时器
    NSTimer   *showTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval
                                                            target:self
                                                          selector:@selector(handleTimer:)
                                                          userInfo:nil
                                                           repeats:NO];
    
    showTimer.fireDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];

 scheduled 会自动执行,不用fire 也可以。fire是立即执行的意思,会忽略firedate这个参数。

上面的程序会在1秒后执行。

 

分类:

技术点:

相关文章:

  • 2021-04-19
  • 2022-12-23
  • 2021-11-30
  • 2021-11-30
  • 2022-12-23
  • 2022-02-17
  • 2022-01-13
  • 2021-11-30
猜你喜欢
  • 2022-01-20
  • 2021-12-03
  • 2021-12-09
  • 2021-11-18
  • 2021-11-30
  • 2022-02-07
  • 2022-12-23
相关资源
相似解决方案