• 工具---定时器


    定时器的写法:

    第一种:scheduled的初始化方法将以默认mode直接添加到当前的runloop中.

    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    
    - (void)timerAction:(NSTimer *)sender
    {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }
    

     第二种: 不用scheduled方式初始化的,需要手动addTimer:forMode: 将timer添加到一个runloop中

     NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES]; 
        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    
    
    
    - (void)timerAction:(NSTimer *)sender
    {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }
    
  • 相关阅读:
    按键
    bga植球
    数码管
    蜂鸣器
    LED流水灯
    sysTick定时器
    位带
    Android开发
    JavaScript修改src
    JSP笔记
  • 原文地址:https://www.cnblogs.com/bachl/p/4769742.html
Copyright © 2020-2023  润新知