zoukankan      html  css  js  c++  java
  • 工具---定时器

    定时器的写法:

    第一种: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];
    }
    
  • 相关阅读:
    python笔记-2
    python笔记-1
    生成列表
    内置函数
    装饰器、包的导入
    python3 编码
    python3 初识函数
    python3 文件读写
    python3 流程控制
    python3 数据类型
  • 原文地址:https://www.cnblogs.com/bachl/p/4769742.html
Copyright © 2011-2022 走看看